53 #include "llvm/ADT/STLExtras.h"
54 #include "llvm/ADT/StringExtras.h"
55 #include "llvm/Support/Casting.h"
56 #include "llvm/Support/ConvertUTF.h"
57 #include "llvm/Support/SaveAndRestore.h"
58 #include "llvm/Support/TypeSize.h"
61 using namespace clang;
68 if (ParsingInitForAutoVars.count(D))
78 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
84 if (TreatUnavailableAsInvalid &&
85 isUnavailableAlignedAllocationFunction(*FD))
94 if (isa<UnresolvedUsingIfExistsDecl>(D))
102 if (
const auto *A = D->
getAttr<UnusedAttr>()) {
105 if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
106 A->getSemanticSpelling() != UnusedAttr::C2x_maybe_unused) {
108 if (DC && !DC->
hasAttr<UnusedAttr>())
109 S.
Diag(Loc, diag::warn_used_but_marked_unused) << D;
118 if (
Decl->isDefaulted()) {
125 DiagnoseDeletedDefaultedFunction(
Decl);
129 auto *Ctor = dyn_cast<CXXConstructorDecl>(
Decl);
130 if (Ctor && Ctor->isInheritingConstructor())
131 return NoteDeletedInheritingConstructor(Ctor);
141 if (I->getStorageClass() !=
SC_None)
168 if (!Current->isInlined())
170 if (!Current->isExternallyVisible())
186 if (!DowngradeWarning && UsedFn)
189 S.
Diag(Loc, DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet
190 : diag::ext_internal_in_extern_inline)
195 S.
Diag(D->getCanonicalDecl()->getLocation(), diag::note_entity_declared_at)
205 Diag(DeclBegin, diag::note_convert_inline_to_static)
224 bool ObjCPropertyAccess,
225 bool AvoidPartialAvailabilityChecks,
227 bool SkipTrailingRequiresClause) {
229 if (getLangOpts().
CPlusPlus && isa<FunctionDecl>(D)) {
233 if (Pos != SuppressedDiagnostics.end()) {
235 Diag(Suppressed.first, Suppressed.second);
246 if (cast<FunctionDecl>(D)->isMain())
247 Diag(Loc, diag::ext_main_used);
249 diagnoseUnavailableAlignedAllocation(*cast<FunctionDecl>(D), Loc);
253 if (ParsingInitForAutoVars.count(D)) {
254 if (isa<BindingDecl>(D)) {
255 Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer)
258 Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer)
259 << D->
getDeclName() << cast<VarDecl>(D)->getType();
266 if (FD->isDeleted()) {
267 auto *Ctor = dyn_cast<CXXConstructorDecl>(FD);
268 if (Ctor && Ctor->isInheritingConstructor())
269 Diag(Loc, diag::err_deleted_inherited_ctor_use)
271 << Ctor->getInheritedConstructor().getConstructor()->getParent();
273 Diag(Loc, diag::err_deleted_function_use);
274 NoteDeletedFunction(FD);
286 if (!SkipTrailingRequiresClause && FD->getTrailingRequiresClause()) {
288 if (CheckFunctionConstraints(FD, Satisfaction, Loc,
295 diag::err_reference_to_function_with_unsatisfied_constraints)
297 DiagnoseUnsatisfiedConstraint(Satisfaction);
304 if (getLangOpts().
CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
305 DeduceReturnType(FD, Loc))
308 if (getLangOpts().
CUDA && !CheckCUDACall(Loc, FD))
311 if (getLangOpts().SYCLIsDevice && !checkSYCLDeviceFunction(Loc, FD))
315 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
317 if (MD->getParent()->isLambda() &&
318 ((isa<CXXConstructorDecl>(MD) &&
319 cast<CXXConstructorDecl>(MD)->isDefaultConstructor()) ||
320 MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) {
321 Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign)
322 << !isa<CXXConstructorDecl>(MD);
326 auto getReferencedObjCProp = [](
const NamedDecl *D) ->
328 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
333 if (diagnoseArgIndependentDiagnoseIfAttrs(ObjCPDecl, Loc))
335 }
else if (diagnoseArgIndependentDiagnoseIfAttrs(D, Loc)) {
343 auto *DRD = dyn_cast<OMPDeclareReductionDecl>(CurContext);
344 if (LangOpts.OpenMP && DRD && !CurContext->containsDecl(D) &&
346 Diag(Loc, diag::err_omp_wrong_var_in_declare_reduction)
347 << getCurFunction()->HasOMPDeclareReductionCombiner;
357 if (LangOpts.OpenMP && isa<VarDecl>(D) &&
358 !isOpenMPDeclareMapperVarDeclAllowed(cast<VarDecl>(D))) {
359 Diag(Loc, diag::err_omp_declare_mapper_wrong_var)
360 << getOpenMPDeclareMapperVarName();
365 if (
const auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(D)) {
366 Diag(Loc, diag::err_use_of_empty_using_if_exists);
367 Diag(EmptyD->getLocation(), diag::note_empty_using_if_exists_here);
371 DiagnoseAvailabilityOfDecl(D, Locs, UnknownObjCClass, ObjCPropertyAccess,
372 AvoidPartialAvailabilityChecks, ClassReceiver);
378 if (
auto *VD = dyn_cast<ValueDecl>(D))
379 checkTypeSupport(VD->getType(), Loc, VD);
381 if (LangOpts.SYCLIsDevice || (LangOpts.OpenMP && LangOpts.OpenMPIsDevice)) {
383 if (
const auto *VD = dyn_cast<VarDecl>(D))
385 targetDiag(*Locs.begin(), diag::err_thread_unsupported);
388 if (isa<ParmVarDecl>(D) && isa<RequiresExprBodyDecl>(D->
getDeclContext()) &&
389 !isUnevaluatedContext()) {
393 Diag(Loc, diag::err_requires_expr_parameter_referenced_in_evaluated_context)
408 const SentinelAttr *
attr = D->
getAttr<SentinelAttr>();
413 unsigned numFormalParams;
417 enum CalleeType { CT_Function, CT_Method, CT_Block } calleeType;
420 numFormalParams = MD->param_size();
421 calleeType = CT_Method;
422 }
else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
423 numFormalParams = FD->param_size();
424 calleeType = CT_Function;
425 }
else if (isa<VarDecl>(D)) {
431 calleeType = CT_Function;
434 calleeType = CT_Block;
440 numFormalParams = proto->getNumParams();
452 unsigned nullPos =
attr->getNullPos();
453 assert((nullPos == 0 || nullPos == 1) &&
"invalid null position on sentinel");
454 numFormalParams = (nullPos > numFormalParams ? 0 : numFormalParams - nullPos);
457 unsigned numArgsAfterSentinel =
attr->getSentinel();
461 if (Args.size() < numFormalParams + numArgsAfterSentinel + 1) {
468 Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1];
469 if (!sentinelExpr)
return;
479 if (calleeType == CT_Method && PP.isMacroDefined(
"nil"))
482 NullValue =
"nullptr";
483 else if (PP.isMacroDefined(
"NULL"))
486 NullValue =
"(void*) 0";
489 Diag(Loc, diag::warn_missing_sentinel) <<
int(calleeType);
491 Diag(MissingNilLoc, diag::warn_missing_sentinel)
515 assert(!Ty.
isNull() &&
"DefaultFunctionArrayConversion - missing type");
519 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
524 CK_FunctionToPointerDecay).get();
539 CK_ArrayToPointerDecay);
555 if (UO && UO->getOpcode() == UO_Deref &&
556 UO->getSubExpr()->getType()->isPointerType()) {
558 UO->getSubExpr()->getType()->getPointeeType().getAddressSpace();
561 UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant(
563 !UO->getType().isVolatileQualified()) {
565 S.
PDiag(diag::warn_indirection_through_null)
566 << UO->getSubExpr()->getSourceRange());
568 S.
PDiag(diag::note_indirection_through_null));
600 if (ObjectSetClass) {
644 assert(!T.
isNull() &&
"r-value conversion on typeless expression?");
667 if (getLangOpts().
OpenCL &&
668 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp16", getLangOpts()) &&
677 NamedDecl *ObjectGetClass = LookupSingleName(TUScope,
684 SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()),
")");
709 ExprResult Res = CheckLValueToRValueConversionOperand(E);
717 Cleanup.setExprNeedsCleanups(
true);
720 Cleanup.setExprNeedsCleanups(
true);
726 CurFPFeatureOverrides());
732 T = Atomic->getValueType().getUnqualifiedType();
741 ExprResult Res = DefaultFunctionArrayConversion(E, Diagnose);
744 Res = DefaultLvalueConversion(Res.
get());
759 CK_FunctionToPointerDecay);
763 Res = DefaultLvalueConversion(Res.
get());
776 ExprResult Res = DefaultFunctionArrayLvalueConversion(E);
782 assert(!Ty.
isNull() &&
"UsualUnaryConversions - missing type");
786 (getLangOpts().getFPEvalMethod() !=
787 LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine ||
788 PP.getLastFPEvalPragmaLocation().isValid())) {
789 switch (EvalMethod) {
791 llvm_unreachable(
"Unrecognized float evaluation method");
794 llvm_unreachable(
"Float evaluation method should be set by now");
800 ? ImpCastExprToType(E,
802 CK_FloatingComplexCast)
803 : ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast);
811 CK_FloatingComplexCast)
819 if (Ty->
isHalfType() && !getLangOpts().NativeHalfType)
820 return ImpCastExprToType(Res.
get(), Context.
FloatTy, CK_FloatingCast);
841 E = ImpCastExprToType(E, PTy, CK_IntegralCast).get();
846 E = ImpCastExprToType(E, PT, CK_IntegralCast).get();
859 assert(!Ty.
isNull() &&
"DefaultArgumentPromotion - missing type");
871 if (BTy && (BTy->
getKind() == BuiltinType::Half ||
873 if (getLangOpts().OpenCL &&
874 !getOpenCLOptions().isAvailableOption(
"cl_khr_fp64", getLangOpts())) {
875 if (BTy->
getKind() == BuiltinType::Half) {
876 E = ImpCastExprToType(E, Context.
FloatTy, CK_FloatingCast).get();
879 E = ImpCastExprToType(E, Context.
DoubleTy, CK_FloatingCast).get();
883 getLangOpts().getExtendIntArgs() ==
891 : ImpCastExprToType(E, Context.
LongLongTy, CK_IntegralCast).get();
893 "Unexpected typesize for LongLongTy");
953 if (!Record->hasNonTrivialCopyConstructor() &&
954 !Record->hasNonTrivialMoveConstructor() &&
955 !Record->hasNonTrivialDestructor())
956 return VAK_ValidInCXX11;
964 if (getLangOpts().MSVCCompat)
965 return VAK_MSVCUndefined;
969 return VAK_Undefined;
979 case VAK_ValidInCXX11:
982 PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
989 PDiag(diag::warn_pass_class_arg_to_vararg)
990 << Ty << CT << hasCStrMethod(E) <<
".c_str()");
995 case VAK_MSVCUndefined:
997 PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
1004 diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
1008 PDiag(diag::err_cannot_pass_objc_interface_to_vararg)
1012 << isa<InitListExpr>(E) << Ty << CT;
1023 if (PlaceholderTy->getKind() == BuiltinType::ARCUnbridgedCast &&
1024 (CT == VariadicMethod ||
1025 (FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>()))) {
1026 E = stripARCUnbridgedCast(E);
1030 ExprResult ExprRes = CheckPlaceholderExpr(E);
1037 ExprResult ExprRes = DefaultArgumentPromotion(E);
1043 maybeExtendBlockObject(ExprRes);
1049 if (isValidVarArgType(E->
getType()) == VAK_Undefined) {
1054 Name.setIdentifier(PP.getIdentifierInfo(
"__builtin_trap"),
1056 ExprResult TrapFn = ActOnIdExpression(TUScope, SS, TemplateKWLoc, Name,
1064 if (Call.isInvalid())
1068 ActOnBinOp(TUScope, E->
getBeginLoc(), tok::comma, Call.get(), E);
1069 if (Comma.isInvalid())
1076 diag::err_call_incomplete_argument))
1093 if (SkipCast)
return false;
1098 CK_FloatingRealToComplex);
1102 CK_IntegralComplexToFloatingComplex);
1120 bool PromotePrecision) {
1125 if (PromotePrecision) {
1130 if (LongerIsComplex)
1142 QualType RHSType,
bool IsCompAssign) {
1167 bool ConvertFloat,
bool ConvertInt) {
1172 CK_IntegralToFloating);
1183 CK_IntegralComplexToFloatingComplex);
1188 CK_FloatingRealToComplex);
1197 QualType RHSType,
bool IsCompAssign) {
1207 else if (!IsCompAssign)
1209 return LHSFloat ? LHSType : RHSType;
1214 if (LHSFloat && RHSFloat) {
1221 assert(order < 0 &&
"illegal float comparison");
1255 QualType LHSElem = LHSComplex ? LHSComplex->getElementType() : LHSType;
1261 if ((&LHSSem != &llvm::APFloat::PPCDoubleDouble() ||
1262 &RHSSem != &llvm::APFloat::IEEEquad()) &&
1263 (&LHSSem != &llvm::APFloat::IEEEquad() ||
1264 &RHSSem != &llvm::APFloat::PPCDoubleDouble()))
1281 CK_IntegralComplexCast);
1287 template <PerformCastFn doLHSCast, PerformCastFn doRHSCast>
1290 QualType RHSType,
bool IsCompAssign) {
1295 if (LHSSigned == RHSSigned) {
1298 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1300 }
else if (!IsCompAssign)
1301 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1303 }
else if (order != (LHSSigned ? 1 : -1)) {
1307 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1309 }
else if (!IsCompAssign)
1310 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1317 RHS = (*doRHSCast)(S, RHS.
get(), LHSType);
1319 }
else if (!IsCompAssign)
1320 LHS = (*doLHSCast)(S, LHS.
get(), RHSType);
1329 RHS = (*doRHSCast)(S, RHS.
get(), result);
1331 LHS = (*doLHSCast)(S, LHS.
get(), result);
1341 bool IsCompAssign) {
1345 if (LHSComplexInt && RHSComplexInt) {
1349 handleIntegerConversion<doComplexIntegralCast, doComplexIntegralCast>
1350 (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign);
1355 if (LHSComplexInt) {
1358 handleIntegerConversion<doComplexIntegralCast, doIntegralCast>
1359 (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign);
1362 CK_IntegralRealToComplex);
1367 assert(RHSComplexInt);
1371 handleIntegerConversion<doIntegralCast, doComplexIntegralCast>
1372 (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign);
1377 CK_IntegralRealToComplex);
1386 assert(BTy &&
"Expected a builtin type.");
1388 switch (BTy->getKind()) {
1389 case BuiltinType::ShortFract:
1390 case BuiltinType::UShortFract:
1391 case BuiltinType::SatShortFract:
1392 case BuiltinType::SatUShortFract:
1394 case BuiltinType::Fract:
1395 case BuiltinType::UFract:
1396 case BuiltinType::SatFract:
1397 case BuiltinType::SatUFract:
1399 case BuiltinType::LongFract:
1400 case BuiltinType::ULongFract:
1401 case BuiltinType::SatLongFract:
1402 case BuiltinType::SatULongFract:
1404 case BuiltinType::ShortAccum:
1405 case BuiltinType::UShortAccum:
1406 case BuiltinType::SatShortAccum:
1407 case BuiltinType::SatUShortAccum:
1409 case BuiltinType::Accum:
1410 case BuiltinType::UAccum:
1411 case BuiltinType::SatAccum:
1412 case BuiltinType::SatUAccum:
1414 case BuiltinType::LongAccum:
1415 case BuiltinType::ULongAccum:
1416 case BuiltinType::SatLongAccum:
1417 case BuiltinType::SatULongAccum:
1420 if (BTy->isInteger())
1422 llvm_unreachable(
"Unexpected fixed point or integer type");
1434 "Expected at least one of the operands to be a fixed point type");
1437 "Special fixed point arithmetic operation conversions are only "
1438 "applied to ints or other fixed point types");
1460 QualType ResultTy = LHSTyRank > RHSTyRank ? LHSTy : RHSTy;
1482 REnum = R->isUnscopedEnumerationType();
1484 if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
1487 ? diag::warn_arith_conv_enum_float_cxx20
1488 : diag::warn_arith_conv_enum_float)
1490 << (
int)ACK << LEnum << L << R;
1491 }
else if (!IsCompAssign && LEnum && REnum &&
1495 !R->castAs<
EnumType>()->getDecl()->hasNameForLinkage()) {
1500 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
1501 : diag::warn_arith_conv_mixed_anon_enum_types;
1506 ? diag::warn_conditional_mixed_enum_types_cxx20
1507 : diag::warn_conditional_mixed_enum_types;
1512 ? diag::warn_comparison_mixed_enum_types_cxx20
1513 : diag::warn_comparison_mixed_enum_types;
1516 ? diag::warn_arith_conv_mixed_enum_types_cxx20
1517 : diag::warn_arith_conv_mixed_enum_types;
1520 << (
int)ACK << L << R;
1533 if (ACK != ACK_CompAssign) {
1534 LHS = UsualUnaryConversions(LHS.
get());
1539 RHS = UsualUnaryConversions(RHS.
get());
1550 LHSType = AtomicLHS->getValueType();
1562 QualType LHSUnpromotedType = LHSType;
1566 if (!LHSBitfieldPromoteTy.
isNull())
1567 LHSType = LHSBitfieldPromoteTy;
1568 if (LHSType != LHSUnpromotedType && ACK != ACK_CompAssign)
1569 LHS = ImpCastExprToType(LHS.
get(), LHSType, CK_IntegralCast);
1585 ACK == ACK_CompAssign);
1590 ACK == ACK_CompAssign);
1595 ACK == ACK_CompAssign);
1601 return handleIntegerConversion<doIntegralCast, doIntegralCast>
1602 (*
this, LHS, RHS, LHSType, RHSType, ACK == ACK_CompAssign);
1614 Expr *ControllingExpr,
1617 unsigned NumAssocs = ArgTypes.size();
1618 assert(NumAssocs == ArgExprs.size());
1621 for (
unsigned i = 0; i < NumAssocs; ++i) {
1623 (void) GetTypeFromParser(ArgTypes[i], &Types[i]);
1629 CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, ControllingExpr,
1639 Expr *ControllingExpr,
1642 unsigned NumAssocs = Types.size();
1643 assert(NumAssocs == Exprs.size());
1650 ExprResult R = DefaultFunctionArrayLvalueConversion(ControllingExpr);
1653 ControllingExpr = R.
get();
1656 bool TypeErrorFound =
false,
1658 ContainsUnexpandedParameterPack
1663 if (!inTemplateInstantiation() && !IsResultDependent &&
1666 diag::warn_side_effects_unevaluated_context);
1668 for (
unsigned i = 0; i < NumAssocs; ++i) {
1669 if (Exprs[i]->containsUnexpandedParameterPack())
1670 ContainsUnexpandedParameterPack =
true;
1673 if (Types[i]->getType()->containsUnexpandedParameterPack())
1674 ContainsUnexpandedParameterPack =
true;
1676 if (Types[i]->getType()->isDependentType()) {
1677 IsResultDependent =
true;
1682 if (Types[i]->getType()->isIncompleteType())
1683 D = diag::err_assoc_type_incomplete;
1684 else if (!Types[i]->getType()->isObjectType())
1685 D = diag::err_assoc_type_nonobject;
1686 else if (Types[i]->getType()->isVariablyModifiedType())
1687 D = diag::err_assoc_type_variably_modified;
1703 unsigned Reason = 0;
1712 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1713 diag::warn_unreachable_association)
1714 << QT << (Reason - 1);
1718 Diag(Types[i]->getTypeLoc().getBeginLoc(), D)
1719 << Types[i]->getTypeLoc().getSourceRange()
1720 << Types[i]->getType();
1721 TypeErrorFound =
true;
1726 for (
unsigned j = i+1; j < NumAssocs; ++j)
1727 if (Types[j] && !Types[j]->getType()->isDependentType() &&
1729 Types[j]->getType())) {
1730 Diag(Types[j]->getTypeLoc().getBeginLoc(),
1731 diag::err_assoc_compatible_types)
1732 << Types[j]->getTypeLoc().getSourceRange()
1733 << Types[j]->getType()
1734 << Types[i]->getType();
1735 Diag(Types[i]->getTypeLoc().getBeginLoc(),
1736 diag::note_compat_assoc)
1737 << Types[i]->getTypeLoc().getSourceRange()
1738 << Types[i]->getType();
1739 TypeErrorFound =
true;
1749 if (IsResultDependent)
1751 Exprs, DefaultLoc, RParenLoc,
1752 ContainsUnexpandedParameterPack);
1755 unsigned DefaultIndex = -1
U;
1759 for (
unsigned i = 0; i < NumAssocs; ++i) {
1764 Types[i]->getType()))
1765 CompatIndices.push_back(i);
1771 if (CompatIndices.size() > 1) {
1775 Diag(ControllingExpr->
getBeginLoc(), diag::err_generic_sel_multi_match)
1778 for (
unsigned I : CompatIndices) {
1779 Diag(Types[I]->getTypeLoc().getBeginLoc(),
1780 diag::note_compat_assoc)
1781 << Types[I]->getTypeLoc().getSourceRange()
1782 << Types[I]->getType();
1790 if (DefaultIndex == -1
U && CompatIndices.size() == 0) {
1804 unsigned ResultIndex =
1805 CompatIndices.size() ? CompatIndices[0] : DefaultIndex;
1808 Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc,
1809 ContainsUnexpandedParameterPack, ResultIndex);
1827 assert(Args.size() <= 2 &&
"too many arguments for literal operator");
1830 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
1831 ArgTy[ArgIdx] = Args[ArgIdx]->getType();
1832 if (ArgTy[ArgIdx]->isArrayType())
1859 assert(!StringToks.empty() &&
"Must have at least one string!");
1866 for (
const Token &Tok : StringToks)
1867 StringTokLocs.push_back(Tok.getLocation());
1874 }
else if (
Literal.isUTF8()) {
1875 if (getLangOpts().Char8)
1878 }
else if (
Literal.isUTF16()) {
1881 }
else if (
Literal.isUTF32()) {
1884 }
else if (
Literal.isPascal()) {
1892 Diag(StringTokLocs.front(), diag::warn_cxx20_compat_utf8_string);
1898 auto RemovalDiag = PDiag(diag::note_cxx20_compat_utf8_string_remove_u8);
1900 for (
const Token &Tok : StringToks) {
1901 if (Tok.getKind() == tok::utf8_string_literal) {
1903 RemovalDiagLoc = Tok.getLocation();
1907 getSourceManager(), getLangOpts())));
1910 Diag(RemovalDiagLoc, RemovalDiag);
1920 StringTokLocs.size());
1921 if (
Literal.getUDSuffix().empty())
1932 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_string_udl));
1947 LookupResult R(*
this, OpName, UDSuffixLoc, LookupOrdinaryName);
1948 switch (LookupLiteralOperator(UDLScope, R, ArgTy,
1957 Expr *Args[] = { Lit, LenArg };
1959 return BuildLiteralOperatorCall(R, OpNameInfo, Args, StringTokLocs.back());
1962 case LOLR_Template: {
1967 return BuildLiteralOperatorCall(R, OpNameInfo, std::nullopt,
1968 StringTokLocs.back(), &ExplicitArgs);
1971 case LOLR_StringTemplatePack: {
1982 for (
unsigned I = 0, N = Lit->
getLength(); I != N; ++I) {
1988 return BuildLiteralOperatorCall(R, OpNameInfo, std::nullopt,
1989 StringTokLocs.back(), &ExplicitArgs);
1992 case LOLR_ErrorNoDiagnostic:
1993 llvm_unreachable(
"unexpected literal operator lookup result");
1997 llvm_unreachable(
"unexpected literal operator lookup result");
2005 return BuildDeclRefExpr(D, Ty, VK, NameInfo, SS);
2016 return BuildDeclRefExpr(D, Ty, VK, NameInfo, NNS, FoundD, TemplateKWLoc,
2029 auto *DRE = dyn_cast<DeclRefExpr>(VD->
getInit());
2032 auto *Referee = dyn_cast<VarDecl>(DRE->getDecl());
2033 if (!Referee || !Referee->hasGlobalStorage() ||
2034 Referee->hasAttr<CUDADeviceAttr>())
2040 auto *MD = dyn_cast_or_null<CXXMethodDecl>(S.
CurContext);
2041 if (MD && MD->getParent()->isLambda() &&
2042 MD->getOverloadedOperator() == OO_Call && MD->hasAttr<CUDADeviceAttr>() &&
2051 if (isUnevaluatedContext())
2064 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2065 if (VD->getType()->isReferenceType() &&
2066 !(getLangOpts().OpenMP && isOpenMPCapturedDecl(D)) &&
2068 VD->isUsableInConstantExpressions(Context))
2085 bool RefersToCapturedVariable = isa<VarDecl, BindingDecl>(D) &&
2086 NeedToCaptureVariable(D, NameInfo.
getLoc());
2089 Context, NNS, TemplateKWLoc, D, RefersToCapturedVariable, NameInfo, Ty,
2090 VK, FoundD, TemplateArgs, getNonOdrUseReasonInCurrentContext(D));
2091 MarkDeclRefReferenced(E);
2107 if (
auto *NewFPT = ResolveExceptionSpec(NameInfo.
getLoc(), FPT))
2112 if (getLangOpts().ObjCWeak && isa<VarDecl>(D) &&
2114 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->
getBeginLoc()))
2115 getCurFunction()->recordUseOfWeak(E);
2119 FD = IFD->getAnonField();
2121 UnusedPrivateFields.remove(FD);
2129 if (
auto *BD = dyn_cast<BindingDecl>(D))
2130 if (
auto *BE = BD->getBinding())
2155 Id.TemplateId->NumArgs);
2156 translateTemplateArguments(TemplateArgsPtr, Buffer);
2161 TemplateArgs = &Buffer;
2163 NameInfo = GetNameFromUnqualifiedId(
Id);
2164 TemplateArgs =
nullptr;
2171 unsigned DiagnosticID,
unsigned DiagnosticSuggestID) {
2178 SemaRef.
Diag(TypoLoc, diag::err_no_member) << Typo << Ctx
2181 SemaRef.
Diag(TypoLoc, DiagnosticID) << Typo;
2186 bool DroppedSpecifier =
2189 ? diag::note_implicit_param_decl
2190 : diag::note_previous_decl;
2193 SemaRef.
PDiag(NoteID));
2196 << Typo << Ctx << DroppedSpecifier
2198 SemaRef.
PDiag(NoteID));
2213 bool isDefaultArgument =
2214 !CodeSynthesisContexts.empty() &&
2215 CodeSynthesisContexts.back().Kind ==
2216 CodeSynthesisContext::DefaultFunctionArgumentInstantiation;
2217 CXXMethodDecl *CurMethod = dyn_cast<CXXMethodDecl>(CurContext);
2218 bool isInstance = CurMethod && CurMethod->
isInstance() &&
2227 unsigned DiagID = diag::err_found_in_dependent_base;
2228 unsigned NoteID = diag::note_member_declared_at;
2230 DiagID = getLangOpts().MSVCCompat ? diag::ext_found_later_in_class
2231 : diag::err_found_later_in_class;
2232 }
else if (getLangOpts().MSVCCompat) {
2233 DiagID = diag::ext_found_in_dependent_base;
2234 NoteID = diag::note_dependent_member_use;
2250 Diag(D->getLocation(), NoteID);
2259 if (isDefaultArgument && ((*R.begin())->isCXXInstanceMember())) {
2260 Diag(R.getNameLoc(), diag::err_member_call_without_object);
2277 unsigned diagnostic = diag::err_undeclared_var_use;
2278 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
2282 diagnostic = diag::err_undeclared_use;
2283 diagnostic_suggest = diag::err_undeclared_use_suggest;
2292 if (isa<CXXRecordDecl>(DC)) {
2293 LookupQualifiedName(R, DC);
2303 AddOverloadedCallCandidates(R, ExplicitTemplateArgs, Args, Candidates);
2308 R.
addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
2312 return DiagnoseDependentMemberLookup(R);
2325 assert(!ExplicitTemplateArgs &&
2326 "Diagnosing an empty lookup with explicit template args!");
2327 *Out = CorrectTypoDelayed(
2330 emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args,
2331 diagnostic, diagnostic_suggest);
2333 nullptr, CTK_ErrorRecovery);
2338 S, &SS, CCC, CTK_ErrorRecovery))) {
2340 bool DroppedSpecifier =
2344 bool AcceptableWithRecovery =
false;
2345 bool AcceptableWithoutRecovery =
false;
2354 dyn_cast<FunctionTemplateDecl>(CD))
2355 AddTemplateOverloadCandidate(
2358 else if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(CD))
2359 if (!ExplicitTemplateArgs || ExplicitTemplateArgs->
size() == 0)
2365 ND = Best->FoundDecl;
2366 Corrected.setCorrectionDecl(ND);
2370 Corrected.setCorrectionDecl(ND);
2382 Record = cast<CXXRecordDecl>(
2388 AcceptableWithRecovery = isa<ValueDecl>(UnderlyingND) ||
2389 isa<FunctionTemplateDecl>(UnderlyingND);
2395 AcceptableWithoutRecovery = isa<TypeDecl>(UnderlyingND) ||
2397 isa<ObjCInterfaceDecl>(UnderlyingND);
2401 AcceptableWithoutRecovery =
true;
2404 if (AcceptableWithRecovery || AcceptableWithoutRecovery) {
2406 ? diag::note_implicit_param_decl
2407 : diag::note_previous_decl;
2409 diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2410 PDiag(NoteID), AcceptableWithRecovery);
2412 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2413 << Name << computeDeclContext(SS,
false)
2414 << DroppedSpecifier << SS.
getRange(),
2415 PDiag(NoteID), AcceptableWithRecovery);
2418 return !AcceptableWithRecovery;
2427 << Name << computeDeclContext(SS,
false)
2454 else if (
auto *MD = dyn_cast<CXXMethodDecl>(S.
CurContext))
2462 auto DB = S.
Diag(Loc, diag::ext_undeclared_unqual_id_with_dependent_base);
2463 DB << NameInfo.
getName() << RD;
2465 if (!ThisType.
isNull()) {
2468 Context,
nullptr, ThisType,
true,
2470 nullptr, NameInfo, TemplateArgs);
2487 bool HasTrailingLParen,
bool IsAddressOfOperand,
2489 bool IsInlineAsmIdentifier,
Token *KeywordReplacement) {
2490 assert(!(IsAddressOfOperand && HasTrailingLParen) &&
2491 "cannot be direct & operand and have a trailing lparen");
2500 DecomposeUnqualifiedId(
Id, TemplateArgsBuffer, NameInfo, TemplateArgs);
2523 bool DependentID =
false;
2525 Name.getCXXNameType()->isDependentType()) {
2527 }
else if (SS.
isSet()) {
2528 if (
DeclContext *DC = computeDeclContext(SS,
false)) {
2529 if (RequireCompleteDeclContext(SS, DC))
2537 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2538 IsAddressOfOperand, TemplateArgs);
2543 ? LookupObjCImplicitSelfParam
2544 : LookupOrdinaryName);
2545 if (TemplateKWLoc.
isValid() || TemplateArgs) {
2551 bool MemberOfUnknownSpecialization;
2553 if (LookupTemplateName(R, S, SS,
QualType(),
false,
2554 MemberOfUnknownSpecialization, TemplateKWLoc,
2558 if (MemberOfUnknownSpecialization ||
2560 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2561 IsAddressOfOperand, TemplateArgs);
2563 bool IvarLookupFollowUp = II && !SS.
isSet() && getCurMethodDecl();
2564 LookupParsedName(R, S, &SS, !IvarLookupFollowUp);
2569 return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
2570 IsAddressOfOperand, TemplateArgs);
2574 if (IvarLookupFollowUp) {
2575 ExprResult E(LookupInObjCMethod(R, S, II,
true));
2589 if (R.
empty() && HasTrailingLParen && II &&
2590 getLangOpts().implicitFunctionsAllowed()) {
2591 NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S);
2597 bool ADL = UseArgumentDependentLookup(SS, R, HasTrailingLParen);
2599 if (R.
empty() && !ADL) {
2600 if (SS.
isEmpty() && getLangOpts().MSVCCompat) {
2602 TemplateKWLoc, TemplateArgs))
2607 if (IsInlineAsmIdentifier)
2617 "Typo correction callback misconfigured");
2627 if (DiagnoseEmptyLookup(S, SS, R, CCC ? *CCC : DefaultValidator,
nullptr,
2628 std::nullopt, &TE)) {
2629 if (TE && KeywordReplacement) {
2630 auto &
State = getTypoExprState(TE);
2631 auto BestTC =
State.Consumer->getNextCorrection();
2632 if (BestTC.isKeyword()) {
2633 auto *II = BestTC.getCorrectionAsIdentifierInfo();
2634 if (
State.DiagHandler)
2635 State.DiagHandler(BestTC);
2639 KeywordReplacement->
setLocation(BestTC.getCorrectionRange().getBegin());
2642 clearDelayedTypo(TE);
2645 return (
Expr*)
nullptr;
2647 State.Consumer->resetCorrectionStream();
2652 assert(!R.
empty() &&
2653 "DiagnoseEmptyLookup returned false but added no results");
2660 ExprResult E(LookupInObjCMethod(R, S, Ivar->getIdentifier()));
2670 assert(!R.
empty() || ADL);
2696 if (!R.
empty() && (*R.
begin())->isCXXClassMember()) {
2697 bool MightBeImplicitMember;
2698 if (!IsAddressOfOperand)
2699 MightBeImplicitMember =
true;
2701 MightBeImplicitMember =
false;
2703 MightBeImplicitMember =
false;
2705 MightBeImplicitMember =
true;
2707 MightBeImplicitMember = isa<FieldDecl>(R.
getFoundDecl()) ||
2711 if (MightBeImplicitMember)
2712 return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc,
2713 R, TemplateArgs, S);
2716 if (TemplateArgs || TemplateKWLoc.
isValid()) {
2724 "There should only be one declaration found.");
2727 return BuildTemplateIdExpr(SS, TemplateKWLoc, R, ADL, TemplateArgs);
2730 return BuildDeclarationNameExpr(SS, R, ADL);
2749 if (RequireCompleteDeclContext(SS, DC))
2753 LookupQualifiedName(R, DC);
2767 if (
const auto *CD = dyn_cast<CXXRecordDecl>(DC))
2768 if (CD->isInvalidDecl())
2779 unsigned DiagID = diag::err_typename_missing;
2780 if (RecoveryTSI && getLangOpts().MSVCCompat)
2781 DiagID = diag::ext_typename_missing;
2783 auto D =
Diag(Loc, DiagID);
2814 if (!R.
empty() && (*R.
begin())->isCXXClassMember() && !IsAddressOfOperand)
2815 return BuildPossibleImplicitMemberExpr(SS,
2819 return BuildDeclarationNameExpr(SS, R,
false);
2850 LookForIvars =
true;
2851 else if (IsClassMethod)
2852 LookForIvars =
false;
2863 if (IsClassMethod) {
2871 !getLangOpts().DebuggerSupport)
2884 Diag(Loc, diag::warn_ivar_use_hidden) << IV->getDeclName();
2892 Diag(Loc, diag::err_ivar_use_in_class_method) << IV->getDeclName();
2905 "should not reference ivar from this context");
2908 assert(IFace &&
"should not reference ivar from this context");
2916 if (DiagnoseUseOfDecl(IV, Loc))
2927 ActOnIdExpression(S, SelfScopeSpec, TemplateKWLoc, SelfName,
2933 SelfExpr = DefaultLvalueConversion(SelfExpr.
get());
2937 MarkAnyDeclReferenced(Loc, IV,
true);
2941 !IvarBacksCurrentMethodAccessor(IFace, CurMethod, IV))
2949 if (!isUnevaluatedContext() &&
2950 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, Loc))
2951 getCurFunction()->recordUseOfWeak(Result);
2953 if (getLangOpts().ObjCAutoRefCount && !isUnevaluatedContext())
2955 ImplicitlyRetainedSelfLocs.push_back({Loc, BD});
2973 cast<ObjCIvarDecl>(Ivar.
get()));
2975 if (Lookup.
empty() && II && AllowBuiltinCreation)
3015 bool PointerConversions =
false;
3016 if (isa<FieldDecl>(
Member)) {
3020 DestRecordType, FromPtrType
3027 PointerConversions =
true;
3029 DestType = DestRecordType;
3030 FromRecordType = FromType;
3033 if (Method->isStatic())
3036 DestType = Method->getThisType();
3041 PointerConversions =
true;
3043 FromRecordType = FromType;
3044 DestType = DestRecordType;
3049 if (FromAS != DestAS) {
3054 if (PointerConversions)
3095 if (Qualifier && Qualifier->getAsType()) {
3097 assert(QType->
isRecordType() &&
"lookup done with non-record type");
3107 FromLoc, FromRange, &BasePath))
3110 if (PointerConversions)
3113 VK, &BasePath).
get();
3116 FromRecordType = QRecordType;
3127 FromLoc, FromRange, &BasePath,
3137 bool HasTrailingLParen) {
3139 if (!HasTrailingLParen)
3157 if (D->isCXXClassMember())
3166 if (isa<UsingShadowDecl>(D))
3167 D = cast<UsingShadowDecl>(D)->getTargetDecl();
3168 else if (D->getLexicalDeclContext()->isFunctionOrMethod())
3175 if (isa<FunctionDecl>(D)) {
3181 }
else if (!isa<FunctionTemplateDecl>(D))
3194 bool AcceptInvalid) {
3198 if (isa<TypedefNameDecl>(D)) {
3203 if (isa<ObjCInterfaceDecl>(D)) {
3208 if (isa<NamespaceDecl>(D)) {
3220 const auto *FD = dyn_cast<FunctionDecl>(R.
getFoundDecl());
3222 (FD->isCPUDispatchMultiVersion() || FD->isCPUSpecificMultiVersion());
3227 bool AcceptInvalidDecl) {
3268 bool AcceptInvalidDecl) {
3269 assert(D &&
"Cannot refer to a NULL declaration");
3270 assert(!isa<FunctionTemplateDecl>(D) &&
3271 "Cannot refer unambiguously to a function template");
3281 if (
TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) {
3289 if (!isa<ValueDecl, UnresolvedUsingIfExistsDecl>(D)) {
3290 Diag(Loc, diag::err_ref_non_value) << D << SS.
getRange();
3302 auto *VD = cast<ValueDecl>(D);
3305 if (VD->isInvalidDecl() && !AcceptInvalidDecl)
3312 if (!indirectField->isCXXClassMember())
3324 type =
type.getNonPackExpansionType();
3328 #define ABSTRACT_DECL(kind)
3329 #define VALUE(type, base)
3330 #define DECL(type, base) case Decl::type:
3331 #include "clang/AST/DeclNodes.inc"
3332 llvm_unreachable(
"invalid value decl kind");
3335 case Decl::ObjCAtDefsField:
3336 llvm_unreachable(
"forming non-member reference to ivar?");
3340 case Decl::EnumConstant:
3341 case Decl::UnresolvedUsingValue:
3342 case Decl::OMPDeclareReduction:
3343 case Decl::OMPDeclareMapper:
3352 case Decl::IndirectField:
3353 case Decl::ObjCIvar:
3364 case Decl::NonTypeTemplateParm: {
3366 type = reftype->getPointeeType();
3376 if (
type->isRecordType()) {
3377 type =
type.getUnqualifiedType().withConst();
3390 case Decl::VarTemplateSpecialization:
3391 case Decl::VarTemplatePartialSpecialization:
3392 case Decl::Decomposition:
3393 case Decl::OMPCapturedExpr:
3396 type->isVoidType()) {
3402 case Decl::ImplicitParam:
3403 case Decl::ParmVar: {
3413 if (!CapturedType.
isNull())
3414 type = CapturedType;
3426 case Decl::Function: {
3427 if (
unsigned BID = cast<FunctionDecl>(VD)->getBuiltinID()) {
3456 if (!cast<FunctionDecl>(VD)->hasPrototype() && isa<FunctionProtoType>(fty))
3465 case Decl::CXXDeductionGuide:
3466 llvm_unreachable(
"building reference to deduction guide");
3468 case Decl::MSProperty:
3470 case Decl::TemplateParamObject:
3476 case Decl::UnnamedGlobalConstant:
3480 case Decl::CXXMethod:
3485 dyn_cast<FunctionProtoType>(VD->getType()))
3493 if (cast<CXXMethodDecl>(VD)->isStatic()) {
3499 case Decl::CXXConversion:
3500 case Decl::CXXDestructor:
3501 case Decl::CXXConstructor:
3513 if (VD->isInvalidDecl() && E)
3520 Target.resize(CharByteWidth * (Source.size() + 1));
3521 char *ResultPtr = &
Target[0];
3522 const llvm::UTF8 *ErrorPtr;
3524 llvm::ConvertUTF8toWide(CharByteWidth, Source, ResultPtr, ErrorPtr);
3533 Decl *currentDecl =
nullptr;
3535 currentDecl = BSI->TheDecl;
3537 currentDecl = LSI->CallOperator;
3539 currentDecl = CSI->TheCapturedDecl;
3544 Diag(Loc, diag::ext_predef_outside_function);
3550 if (cast<DeclContext>(currentDecl)->isDependentContext())
3556 unsigned Length = Str.length();
3609 default: llvm_unreachable(
"Unknown simple primary expr!");
3624 bool Invalid =
false;
3625 StringRef ThisTok =
PP.
getSpelling(Tok, CharBuffer, &Invalid);
3664 if (
Literal.getUDSuffix().empty())
3674 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_character_udl));
3695 APFloat::opStatus result =
Literal.GetFloatValue(Val);
3699 if ((result & APFloat::opOverflow) ||
3700 ((result & APFloat::opUnderflow) && Val.isZero())) {
3701 unsigned diagnostic;
3703 if (result & APFloat::opOverflow) {
3704 diagnostic = diag::warn_float_overflow;
3705 APFloat::getLargest(Format).toString(buffer);
3707 diagnostic = diag::warn_float_underflow;
3708 APFloat::getSmallest(Format).toString(buffer);
3711 S.
Diag(Loc, diagnostic)
3713 << StringRef(buffer.data(), buffer.size());
3716 bool isExact = (result == APFloat::opOK);
3721 assert(E &&
"Invalid expression");
3728 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_type) << QT;
3738 bool ValueIsPositive = ValueAPS.isStrictlyPositive();
3739 if (!ValueIsPositive || ValueAPS.getActiveBits() > 31) {
3740 Diag(E->
getExprLoc(), diag::err_pragma_loop_invalid_argument_value)
3741 <<
toString(ValueAPS, 10) << ValueIsPositive;
3761 SpellingBuffer.resize(Tok.
getLength() + 1);
3764 bool Invalid =
false;
3765 StringRef TokSpelling =
PP.
getSpelling(Tok, SpellingBuffer, &Invalid);
3783 return ExprError(
Diag(UDSuffixLoc, diag::err_invalid_numeric_udl));
3786 if (
Literal.isFloatingLiteral()) {
3820 if (
Literal.isFloatingLiteral()) {
3824 if (
Literal.GetIntegerValue(ResultVal))
3837 unsigned Length =
Literal.getUDSuffixOffset();
3844 false, StrTy, &TokLoc, 1);
3855 bool CharIsUnsigned =
Context.
CharTy->isUnsignedIntegerType();
3857 for (
unsigned I = 0, N =
Literal.getUDSuffixOffset(); I != N; ++I) {
3858 Value = TokSpelling[I];
3867 llvm_unreachable(
"unexpected literal operator lookup result");
3873 if (
Literal.isFixedPointLiteral()) {
3896 bool isSigned = !
Literal.isUnsigned;
3901 bool Overflowed =
Literal.GetFixedPointValue(Val, scale);
3902 bool ValIsZero = Val.isZero() && !Overflowed;
3905 if (
Literal.isFract && Val == MaxVal + 1 && !ValIsZero)
3911 else if (Val.ugt(MaxVal) || Overflowed)
3916 }
else if (
Literal.isFloatingLiteral()) {
3951 }
else if (!
Literal.isIntegerLiteral()) {
3960 ? diag::warn_cxx20_compat_size_t_suffix
3961 : diag::ext_cxx2b_size_t_suffix
3962 : diag::err_cxx2b_size_t_suffix);
3970 ? diag::warn_c2x_compat_bitint_suffix
3971 : diag::ext_c2x_bitint_suffix);
3980 unsigned BitsNeeded =
3981 Literal.isBitInt ? llvm::APInt::getSufficientBitsNeeded(
3986 if (
Literal.GetIntegerValue(ResultVal)) {
3992 "long long is not intmax_t?");
3999 bool AllowUnsigned =
Literal.isUnsigned ||
Literal.getRadix() != 10;
4005 if (
Literal.MicrosoftInteger) {
4010 Width =
Literal.MicrosoftInteger;
4021 Width =
std::max(ResultVal.getActiveBits(), 1u) +
4022 (
Literal.isUnsigned ? 0u : 1u);
4026 unsigned int MaxBitIntWidth =
4028 if (Width > MaxBitIntWidth) {
4031 Width = MaxBitIntWidth;
4038 ResultVal = ResultVal.zextOrTrunc(Width);
4044 assert(!
Literal.MicrosoftInteger &&
4045 "size_t literals can't be Microsoft literals");
4050 if (ResultVal.isIntN(SizeTSize)) {
4052 if (!
Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
4054 else if (AllowUnsigned)
4066 if (ResultVal.isIntN(IntSize)) {
4068 if (!
Literal.isUnsigned && ResultVal[IntSize-1] == 0)
4070 else if (AllowUnsigned)
4081 if (ResultVal.isIntN(LongSize)) {
4083 if (!
Literal.isUnsigned && ResultVal[LongSize-1] == 0)
4085 else if (AllowUnsigned)
4090 const unsigned LongLongSize =
4095 ? diag::warn_old_implicitly_unsigned_long_cxx
4097 ext_old_implicitly_unsigned_long_cxx
4098 : diag::warn_old_implicitly_unsigned_long)
4099 << (LongLongSize > LongSize ? 0
4112 if (ResultVal.isIntN(LongLongSize)) {
4116 if (!
Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 ||
4119 else if (AllowUnsigned)
4121 Width = LongLongSize;
4127 ? diag::warn_cxx98_compat_longlong
4128 : diag::ext_cxx11_longlong);
4143 diag::ext_integer_literal_too_large_for_signed);
4148 if (ResultVal.getBitWidth() != Width)
4149 ResultVal = ResultVal.trunc(Width);
4165 assert(E &&
"ActOnParenExpr() missing expr");
4181 S.
Diag(Loc, diag::err_vecstep_non_scalar_vector_type)
4187 "Scalar types should always be complete");
4201 (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf ||
4202 TraitKind == UETT_PreferredAlignOf)) {
4204 S.
Diag(Loc, diag::ext_sizeof_alignof_function_type)
4212 unsigned DiagID = S.
LangOpts.OpenCL ? diag::err_opencl_sizeof_alignof_type
4213 : diag::ext_sizeof_alignof_void_type;
4228 S.
Diag(Loc, diag::err_sizeof_nonfragile_interface)
4229 << T << (TraitKind == UETT_SizeOf)
4247 if (!ICE || ICE->
getCastKind() != CK_ArrayToPointerDecay)
4267 bool IsUnevaluatedOperand =
4268 (ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf ||
4269 ExprKind == UETT_PreferredAlignOf || ExprKind == UETT_VecStep);
4270 if (IsUnevaluatedOperand) {
4272 if (Result.isInvalid())
4286 Diag(E->
getExprLoc(), diag::warn_side_effects_unevaluated_context);
4288 if (ExprKind == UETT_VecStep)
4301 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4304 diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4309 E, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4328 if (ExprKind == UETT_SizeOf) {
4330 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DeclRef->getFoundDecl())) {
4331 QualType OType = PVD->getOriginalType();
4336 Diag(PVD->getLocation(), diag::note_declared_at);
4389 if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf ||
4390 ExprKind == UETT_OpenMPRequiredSimdAlign)
4393 if (ExprKind == UETT_VecStep)
4402 OpLoc, ExprType, diag::err_sizeof_alignof_incomplete_or_sizeless_type,
4407 Diag(OpLoc, diag::err_sizeof_alignof_function_type)
4425 S.
Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield)
4432 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Inner)) {
4434 }
else if (
MemberExpr *ME = dyn_cast<MemberExpr>(Inner)) {
4435 D = ME->getMemberDecl();
4455 if (
FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) {
4458 if (!FD->getParent()->isCompleteDefinition()) {
4459 S.
Diag(E->
getExprLoc(), diag::err_alignof_member_of_incomplete_type)
4468 if (!FD->getType()->isReferenceType())
4488 assert(CSI !=
nullptr);
4494 #define TYPE(Class, Base)
4495 #define ABSTRACT_TYPE(Class, Base)
4496 #define NON_CANONICAL_TYPE(Class, Base)
4497 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
4498 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
4499 #include "clang/AST/TypeNodes.inc"
4506 case Type::ExtVector:
4507 case Type::ConstantMatrix:
4510 case Type::TemplateSpecialization:
4511 case Type::ObjCObject:
4512 case Type::ObjCInterface:
4513 case Type::ObjCObjectPointer:
4514 case Type::ObjCTypeParam:
4517 llvm_unreachable(
"type class is never variably-modified!");
4518 case Type::Elaborated:
4519 T = cast<ElaboratedType>(Ty)->getNamedType();
4521 case Type::Adjusted:
4522 T = cast<AdjustedType>(Ty)->getOriginalType();
4530 case Type::BlockPointer:
4533 case Type::LValueReference:
4534 case Type::RValueReference:
4537 case Type::MemberPointer:
4540 case Type::ConstantArray:
4541 case Type::IncompleteArray:
4543 T = cast<ArrayType>(Ty)->getElementType();
4545 case Type::VariableArray: {
4553 (isa<CapturedRegionScopeInfo>(CSI) || isa<LambdaScopeInfo>(CSI)))
4559 case Type::FunctionProto:
4560 case Type::FunctionNoProto:
4561 T = cast<FunctionType>(Ty)->getReturnType();
4565 case Type::UnaryTransform:
4566 case Type::Attributed:
4567 case Type::BTFTagAttributed:
4568 case Type::SubstTemplateTypeParm:
4569 case Type::MacroQualified:
4574 T = cast<TypedefType>(Ty)->desugar();
4576 case Type::Decltype:
4577 T = cast<DecltypeType>(Ty)->desugar();
4580 T = cast<UsingType>(Ty)->desugar();
4583 case Type::DeducedTemplateSpecialization:
4584 T = cast<DeducedType>(Ty)->getDeducedType();
4586 case Type::TypeOfExpr:
4587 T = cast<TypeOfExprType>(Ty)->getUnderlyingExpr()->getType();
4590 T = cast<AtomicType>(Ty)->getValueType();
4616 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
4620 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
4621 DC = LSI->CallOperator;
4622 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
4623 DC = CRSI->TheCapturedDecl;
4624 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
4659 }
else if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
4661 }
else if (ExprKind == UETT_VecStep) {
4663 }
else if (ExprKind == UETT_OpenMPRequiredSimdAlign) {
4667 Diag(E->
getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0;
4710 if (
V.get()->isTypeDependent())
4722 return CT->getElementType();
4725 if (
V.get()->getType()->isArithmeticType())
4726 return V.get()->getType();
4731 if (PR.
get() !=
V.get()) {
4737 S.
Diag(Loc, diag::err_realimag_invalid_type) <<
V.get()->getType()
4738 << (IsReal ?
"__real" :
"__imag");
4749 default: llvm_unreachable(
"Unknown unary op!");
4750 case tok::plusplus: Opc = UO_PostInc;
break;
4751 case tok::minusminus: Opc = UO_PostDec;
break;
4756 if (Result.isInvalid())
return ExprError();
4757 Input = Result.get();
4770 !S.
LangOpts.ObjCSubscriptingLegacyRuntime)
4773 S.
Diag(opLoc, diag::err_arithmetic_nonfragile_interface)
4780 auto *BaseNoParens =
Base->IgnoreParens();
4781 if (
auto *MSProp = dyn_cast<MSPropertyRefExpr>(BaseNoParens))
4782 return MSProp->getPropertyDecl()->getType()->isArrayType();
4783 return isa<MSPropertySubscriptExpr>(BaseNoParens);
4803 if (RTy->isIntegralOrUnscopedEnumerationType()) {
4805 Result = PT->getPointeeType();
4807 Result = AT->getElementType();
4810 Result = PT->getPointeeType();
4812 Result = AT->getElementType();
4815 return Result->isDependentType() ? Result : Ctx.
DependentTy;
4832 if (isa<ParenListExpr>(base)) {
4836 base = result.
get();
4843 auto CheckAndReportCommaError = [
this, base, rbLoc](
Expr *E) {
4844 if (isa<BinaryOperator>(E) && cast<BinaryOperator>(E)->isCommaOp()) {
4845 Diag(E->getExprLoc(), diag::err_matrix_subscript_comma)
4854 !isa<MatrixSubscriptExpr>(base)) {
4855 Diag(base->
getExprLoc(), diag::err_matrix_separate_incomplete_index)
4861 auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
4862 if (matSubscriptE) {
4863 assert(ArgExprs.size() == 1);
4864 if (CheckAndReportCommaError(ArgExprs.front()))
4867 assert(matSubscriptE->isIncomplete() &&
4868 "base has to be an incomplete matrix subscript");
4870 matSubscriptE->getRowIdx(),
4871 ArgExprs.front(), rbLoc);
4879 bool IsMSPropertySubscript =
false;
4882 if (!IsMSPropertySubscript) {
4886 base = result.
get();
4892 assert(ArgExprs.size() == 1);
4893 if (CheckAndReportCommaError(ArgExprs.front()))
4901 Expr *idx = ArgExprs[0];
4902 if ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
4903 (isa<CXXOperatorCallExpr>(idx) &&
4904 cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma)) {
4910 if (ArgExprs.size() == 1 &&
4911 ArgExprs[0]->getType()->isNonOverloadPlaceholderType()) {
4915 ArgExprs[0] = result.
get();
4926 base, ArgExprs.front(),
4939 if (IsMSPropertySubscript) {
4940 assert(ArgExprs.size() == 1);
4958 (ArgExprs.size() != 1 || ArgExprs[0]->getType()->isRecordType())))) {
4965 if (!Res.
isInvalid() && isa<ArraySubscriptExpr>(Res.
get()))
4966 CheckSubscriptAccessOfNoDeref(cast<ArraySubscriptExpr>(Res.
get()));
4990 RowIdx = RowR.
get();
5005 ColumnIdx = ColumnR.
get();
5010 auto IsIndexValid = [&](
Expr *IndexExpr,
unsigned Dim,
5011 bool IsColumnIdx) ->
Expr * {
5019 if (std::optional<llvm::APSInt> Idx =
5021 if ((*Idx < 0 || *Idx >= Dim)) {
5023 << IsColumnIdx << Dim;
5031 "should be able to convert any integer type to size type");
5032 return ConvExpr.
get();
5036 RowIdx = IsIndexValid(RowIdx, MTy->
getNumRows(),
false);
5037 ColumnIdx = IsIndexValid(ColumnIdx, MTy->getNumColumns(),
true);
5038 if (!RowIdx || !ColumnIdx)
5042 MTy->getElementType(), RBLoc);
5045 void Sema::CheckAddressOfNoDeref(
const Expr *E) {
5052 while ((Member = dyn_cast<MemberExpr>(StrippedExpr)) && !
Member->isArrow())
5053 StrippedExpr =
Member->getBase()->IgnoreParenImpCasts();
5055 LastRecord.PossibleDerefs.erase(StrippedExpr);
5066 if (isa<ArrayType>(ResultTy))
5069 if (ResultTy->
hasAttr(attr::NoDeref)) {
5070 LastRecord.PossibleDerefs.insert(E);
5078 if (!(isa<ArrayType>(BaseTy) || isa<PointerType>(BaseTy)))
5083 while ((Member = dyn_cast<MemberExpr>(
Base->IgnoreParenCasts())) &&
5087 if (
const auto *Ptr = dyn_cast<PointerType>(
Base->getType())) {
5088 if (Ptr->getPointeeType()->hasAttr(attr::NoDeref))
5089 LastRecord.PossibleDerefs.insert(E);
5099 if (
Base->hasPlaceholderType() &&
5100 !
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5102 if (Result.isInvalid())
5104 Base = Result.get();
5108 if (Result.isInvalid())
5111 if (Result.isInvalid())
5113 LowerBound = Result.get();
5117 if (Result.isInvalid())
5120 if (Result.isInvalid())
5122 Length = Result.get();
5126 if (Result.isInvalid())
5129 if (Result.isInvalid())
5131 Stride = Result.get();
5135 if (
Base->isTypeDependent() ||
5142 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5154 Diag(
Base->getExprLoc(), diag::err_omp_typecheck_section_value)
5155 <<
Base->getSourceRange());
5161 if (Res.isInvalid())
5163 diag::err_omp_typecheck_section_not_integer)
5165 LowerBound = Res.get();
5175 if (Res.isInvalid())
5177 diag::err_omp_typecheck_section_not_integer)
5191 diag::err_omp_typecheck_section_not_integer)
5206 Diag(
Base->getExprLoc(), diag::err_omp_section_function_type)
5207 << ResultTy <<
Base->getSourceRange();
5212 diag::err_omp_section_incomplete_type,
Base))
5221 if (LowerBoundValue.isNegative()) {
5222 Diag(LowerBound->
getExprLoc(), diag::err_omp_section_not_subset_of_array)
5235 if (LengthValue.isNegative()) {
5236 Diag(Length->
getExprLoc(), diag::err_omp_section_length_negative)
5242 }
else if (ColonLocFirst.
isValid() &&
5248 Diag(ColonLocFirst, diag::err_omp_section_length_undefined)
5259 if (!StrideValue.isStrictlyPositive()) {
5260 Diag(Stride->
getExprLoc(), diag::err_omp_section_stride_non_positive)
5268 if (!
Base->hasPlaceholderType(BuiltinType::OMPArraySection)) {
5270 if (Result.isInvalid())
5272 Base = Result.get();
5276 OK_Ordinary, ColonLocFirst, ColonLocSecond, RBLoc);
5283 if (
Base->hasPlaceholderType()) {
5285 if (Result.isInvalid())
5288 if (Result.isInvalid())
5290 Base = Result.get();
5297 LParenLoc, RParenLoc, Dims, Brackets);
5299 (!
Base->isTypeDependent() &&
5302 diag::err_omp_non_pointer_type_array_shaping_base)
5303 <<
Base->getSourceRange());
5306 bool ErrorFound =
false;
5307 for (
Expr *Dim : Dims) {
5308 if (Dim->hasPlaceholderType()) {
5310 if (Result.isInvalid()) {
5315 if (Result.isInvalid()) {
5321 if (!Dim->isTypeDependent()) {
5324 if (Result.isInvalid()) {
5326 Diag(Dim->getExprLoc(), diag::err_omp_typecheck_shaping_not_integer)
5327 << Dim->getSourceRange();
5332 if (!Dim->isValueDependent() && Dim->EvaluateAsInt(EvResult,
Context)) {
5337 if (!
Value.isStrictlyPositive()) {
5338 Diag(Dim->getExprLoc(), diag::err_omp_shaping_dimension_not_positive)
5340 << Dim->getSourceRange();
5346 NewDims.push_back(Dim);
5351 LParenLoc, RParenLoc, NewDims, Brackets);
5358 bool IsCorrect =
true;
5363 if (!D.Type.getAsOpaquePtr()) {
5368 StartLoc = D.DeclIdentLoc;
5374 bool IsDeclTyDependent =
DeclTy->isDependentType() ||
5375 DeclTy->containsUnexpandedParameterPack() ||
5376 DeclTy->isInstantiationDependentType();
5377 if (!IsDeclTyDependent) {
5381 Diag(StartLoc, diag::err_omp_iterator_not_integral_or_pointer)
5389 Diag(StartLoc, diag::err_omp_iterator_not_integral_or_pointer)
5397 assert(D.DeclIdent &&
"Identifier expected.");
5415 Diag(D.DeclIdentLoc, diag::err_redefinition) << VD->getDeclName();
5428 if (!IsDeclTyDependent &&
Begin && !
Begin->isTypeDependent()) {
5434 if (!IsDeclTyDependent &&
End && !
End->isTypeDependent()) {
5438 Expr *Step = D.Range.Step;
5441 Diag(Step->
getExprLoc(), diag::err_omp_iterator_step_not_integral)
5446 std::optional<llvm::APSInt> Result =
5451 if (Result && Result->isZero()) {
5452 Diag(Step->
getExprLoc(), diag::err_omp_iterator_step_constant_zero)
5458 if (!
Begin || !
End || !IsCorrect) {
5474 if (
Decl *
ID = D.IteratorDecl)
5475 ID->setInvalidDecl();
5518 D.Range.Begin, D.Range.End);
5570 D.IteratorDecl->getBeginLoc(),
nullptr,
5572 CounterVD->setImplicit();
5575 D.IteratorDecl->getBeginLoc());
5581 D.AssignmentLoc, BO_Mul,
5598 cast<VarDecl>(D.IteratorDecl)->getType(),
VK_LValue,
5599 D.IteratorDecl->getBeginLoc());
5614 if (!CounterUpdateRes.
isUsable()) {
5620 if (!CounterUpdateRes.
isUsable()) {
5631 Helpers.assign(
ID.size(), {});
5636 if (
Decl *
ID = D.IteratorDecl)
5637 ID->setInvalidDecl();
5642 LLoc, RLoc,
ID, Helpers);
5657 for (
auto *Op : {LHSExp, RHSExp}) {
5658 Op = Op->IgnoreImplicit();
5659 if (Op->getType()->isArrayType() && !Op->isLValue())
5667 if (Result.isInvalid())
5669 LHSExp = Result.get();
5672 if (Result.isInvalid())
5674 RHSExp = Result.get();
5682 Expr *BaseExpr, *IndexExpr;
5717 Diag(LLoc, diag::err_subscript_nonfragile_interface)
5729 LHSExp = Materialized.
get();
5735 ResultType = VTy->getElementType();
5739 Qualifiers Combined = BaseQuals + MemberQuals;
5740 if (Combined != MemberQuals)
5755 LHSExp = Materialized.
get();
5766 Qualifiers Combined = BaseQuals + MemberQuals;
5767 if (Combined != MemberQuals)
5778 CK_ArrayToPointerDecay).
get();
5784 }
else if (RHSTy->isArrayType()) {
5789 CK_ArrayToPointerDecay).
get();
5796 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_value)
5801 return ExprError(
Diag(LLoc, diag::err_typecheck_subscript_not_integer)
5821 Diag(LLoc, diag::ext_gnu_subscript_void_type)
5831 diag::err_subscript_incomplete_or_sizeless_type, BaseExpr))
5844 auto *CSI = dyn_cast<CapturingScopeInfo>(*I);
5848 if (
auto *LSI = dyn_cast<LambdaScopeInfo>(CSI))
5849 DC = LSI->CallOperator;
5850 else if (
auto *CRSI = dyn_cast<CapturedRegionScopeInfo>(CSI))
5851 DC = CRSI->TheCapturedDecl;
5852 else if (
auto *BSI = dyn_cast<BlockScopeInfo>(CSI))
5870 bool SkipImmediateInvocations) {
5872 assert(!RewrittenInit &&
"Should not have a rewritten init expression yet");
5876 Diag(Param->
getBeginLoc(), diag::err_recursive_default_argument) << FD;
5877 Diag(CallLoc, diag::note_recursive_default_argument_used_here);
5882 Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later)
5885 diag::note_default_argument_declared_here);
5890 assert(!RewrittenInit &&
"Should not have a rewitten init expression yet");
5895 Expr *Init = RewrittenInit ? RewrittenInit : Param->
getInit();
5896 assert(Init &&
"default argument but no initializer?");
5905 if (
auto *InitWithCleanup = dyn_cast<ExprWithCleanups>(Init)) {
5912 assert(!InitWithCleanup->getNumObjects() &&
5913 "default argument expression has capturing blocks?");
5918 SkipImmediateInvocations;
5924 bool HasImmediateCalls =
false;
5930 HasImmediateCalls |= FD->isConsteval();
5939 HasImmediateCalls =
true;
5960 return TraverseStmt(E->
getExpr());
5964 return TraverseStmt(E->
getExpr());
5989 assert(Param->
hasDefaultArg() &&
"can't build nonexistent default arg");
5993 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
5994 InitializationContext =
5996 if (!InitializationContext.has_value())
5997 InitializationContext.emplace(CallLoc, Param,
CurContext);
6015 if (!NestedDefaultChecking)
6016 V.TraverseDecl(Param);
6017 if (
V.HasImmediateCalls) {
6034 CallLoc, FD, Param, Init,
6035 NestedDefaultChecking))
6039 Init, InitializationContext->Context);
6043 assert(Field->hasInClassInitializer());
6046 if (Field->isInvalidDecl())
6049 auto *ParentRD = cast<CXXRecordDecl>(Field->getParent());
6051 std::optional<ExpressionEvaluationContextRecord::InitializationContext>
6052 InitializationContext =
6054 if (!InitializationContext.has_value())
6055 InitializationContext.emplace(Loc, Field,
CurContext);
6057 Expr *Init =
nullptr;
6064 if (!Field->getInClassInitializer()) {
6070 ClassPattern->
lookup(Field->getDeclName());
6073 for (
auto *L : Lookup) {
6074 if ((Pattern = dyn_cast<FieldDecl>(L)))
6077 assert(Pattern &&
"We must have set the Pattern!");
6081 Field->setInvalidDecl();
6093 if (!NestedDefaultChecking)
6094 V.TraverseDecl(Field);
6095 if (
V.HasImmediateCalls) {
6099 NestedDefaultChecking;
6104 Immediate.TransformInitializer(Field->getInClassInitializer(),
6109 Field->setInvalidDecl();
6115 if (Field->getInClassInitializer()) {
6116 Expr *E = Init ? Init : Field->getInClassInitializer();
6117 if (!NestedDefaultChecking)
6124 Field->setInvalidDecl();
6130 Field, InitializationContext->Context,
6149 Diag(Loc, diag::err_default_member_initializer_not_yet_parsed)
6150 << OutermostClass << Field;
6151 Diag(Field->getEndLoc(),
6152 diag::note_default_member_initializer_not_yet_parsed);
6155 Field->setInvalidDecl();
6163 if (isa_and_nonnull<CXXConstructorDecl>(FDecl))
6168 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
6169 if (Method->isInstance())
6184 FunctionName(FuncName) {}
6186 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
6195 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
6196 return std::make_unique<FunctionCallCCC>(*
this);
6216 if (
NamedDecl *ND = Corrected.getFoundDecl()) {
6217 if (Corrected.isOverloaded()) {
6227 ND = Best->FoundDecl;
6228 Corrected.setCorrectionDecl(ND);
6234 ND = ND->getUnderlyingDecl();
6235 if (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND))
6254 bool IsExecConfig) {
6264 bool Invalid =
false;
6273 if (Args.size() < NumParams) {
6274 if (Args.size() < MinArgs) {
6279 ? diag::err_typecheck_call_too_few_args_suggest
6280 : diag::err_typecheck_call_too_few_args_at_least_suggest;
6282 <<
static_cast<unsigned>(Args.size())
6287 ? diag::err_typecheck_call_too_few_args_one
6288 : diag::err_typecheck_call_too_few_args_at_least_one)
6292 ? diag::err_typecheck_call_too_few_args
6293 : diag::err_typecheck_call_too_few_args_at_least)
6294 << FnKind << MinArgs << static_cast<unsigned>(Args.size())
6298 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6305 assert((Call->getNumArgs() == NumParams) &&
6306 "We should have reserved space for the default arguments before!");
6311 if (Args.size() > NumParams) {
6317 ? diag::err_typecheck_call_too_many_args_suggest
6318 : diag::err_typecheck_call_too_many_args_at_most_suggest;
6320 <<
static_cast<unsigned>(Args.size())
6322 }
else if (NumParams == 1 && FDecl &&
6324 Diag(Args[NumParams]->getBeginLoc(),
6325 MinArgs == NumParams
6326 ? diag::err_typecheck_call_too_many_args_one
6327 : diag::err_typecheck_call_too_many_args_at_most_one)
6331 Args.back()->getEndLoc());
6333 Diag(Args[NumParams]->getBeginLoc(),
6334 MinArgs == NumParams
6335 ? diag::err_typecheck_call_too_many_args
6336 : diag::err_typecheck_call_too_many_args_at_most)
6337 << FnKind << NumParams << static_cast<unsigned>(Args.size())
6340 Args.back()->getEndLoc());
6343 if (!TC && FDecl && !FDecl->
getBuiltinID() && !IsExecConfig)
6347 Call->shrinkNumArgs(NumParams);
6358 unsigned TotalNumArgs = AllArgs.size();
6359 for (
unsigned i = 0; i < TotalNumArgs; ++i)
6360 Call->setArg(i, AllArgs[i]);
6362 Call->computeDependence();
6371 bool IsListInitialization) {
6373 bool Invalid =
false;
6376 for (
unsigned i = FirstParam; i < NumParams; i++) {
6381 if (ArgIx < Args.size()) {
6382 Arg = Args[ArgIx++];
6385 diag::err_call_incomplete_argument, Arg))
6389 bool CFAudited =
false;
6391 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6392 (!Param || !Param->
hasAttr<CFConsumedAttr>()))
6395 FDecl && FDecl->
hasAttr<CFAuditedTransferAttr>() &&
6396 (!Param || !Param->
hasAttr<CFConsumedAttr>()))
6402 BE->getBlockDecl()->setDoesNotEscape();
6415 Entity,
SourceLocation(), Arg, IsListInitialization, AllowExplicit);
6421 assert(Param &&
"can't use default arguments without a known callee");
6433 CheckArrayAccess(Arg);
6438 AllArgs.push_back(Arg);
6447 for (
Expr *A : Args.slice(ArgIx)) {
6450 Invalid |=
arg.isInvalid();
6451 AllArgs.push_back(
arg.get());
6456 for (
Expr *A : Args.slice(ArgIx)) {
6459 AllArgs.push_back(Arg.
get());
6464 for (
Expr *A : Args.slice(ArgIx))
6465 CheckArrayAccess(A);
6473 TL = DTL.getOriginalLoc();
6476 << ATL.getLocalSourceRange();
6490 const Expr *ArgExpr) {
6520 Diag(CallLoc, diag::warn_static_array_too_small)
6529 std::optional<CharUnits> ArgSize =
6531 std::optional<CharUnits> ParmSize =
6533 if (ArgSize && ParmSize && *ArgSize < *ParmSize) {
6534 Diag(CallLoc, diag::warn_static_array_too_small)
6536 << (
unsigned)ParmSize->getQuantity() << 1;
6550 if (!placeholder)
return false;
6552 switch (placeholder->
getKind()) {
6554 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
6555 case BuiltinType::Id:
6556 #include "clang/Basic/OpenCLImageTypes.def"
6557 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
6558 case BuiltinType::Id:
6559 #include "clang/Basic/OpenCLExtensionTypes.def"
6562 #define SVE_TYPE(Name, Id, SingletonId) \
6563 case BuiltinType::Id:
6564 #include "clang/Basic/AArch64SVEACLETypes.def"
6565 #define PPC_VECTOR_TYPE(Name, Id, Size) \
6566 case BuiltinType::Id:
6567 #include "clang/Basic/PPCTypes.def"
6568 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
6569 #include "clang/Basic/RISCVVTypes.def"
6570 #define PLACEHOLDER_TYPE(ID, SINGLETON_ID)
6571 #define BUILTIN_TYPE(ID, SINGLETON_ID) case BuiltinType::ID:
6572 #include "clang/AST/BuiltinTypes.def"
6577 case BuiltinType::Overload:
6582 case BuiltinType::ARCUnbridgedCast:
6586 case BuiltinType::PseudoObject:
6591 case BuiltinType::UnknownAny:
6595 case BuiltinType::BoundMember:
6596 case BuiltinType::BuiltinFn:
6597 case BuiltinType::IncompleteMatrixIdx:
6598 case BuiltinType::OMPArraySection:
6599 case BuiltinType::OMPArrayShaping:
6600 case BuiltinType::OMPIterator:
6604 llvm_unreachable(
"bad builtin type kind");
6612 bool hasInvalid =
false;
6613 for (
size_t i = 0, e = args.size(); i != e; i++) {
6616 if (result.
isInvalid()) hasInvalid =
true;
6617 else args[i] = result.
get();
6645 bool NeedsNewDecl =
false;
6658 if (!ParamType->isPointerType() || ParamType.hasAddressSpace() ||
6662 OverloadParams.push_back(ParamType);
6670 NeedsNewDecl =
true;
6683 OverloadParams, EPI);
6692 FT = cast<FunctionProtoType>(OverloadTy);
6693 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i) {
6700 Params.push_back(Parm);
6702 OverloadDecl->setParams(Params);
6704 return OverloadDecl;
6715 !Callee->isVariadic())
6717 if (Callee->getMinRequiredArguments() > ArgExprs.size())
6720 if (
const EnableIfAttr *
Attr =
6723 isa<CXXMethodDecl>(Callee)
6724 ? diag::err_ovl_no_viable_member_function_in_call
6725 : diag::err_ovl_no_viable_function_in_call)
6726 << Callee << Callee->getSourceRange();
6727 S.
Diag(Callee->getLocation(),
6728 diag::note_ovl_candidate_disabled_by_function_cond_attr)
6729 <<
Attr->getCond()->getSourceRange() <<
Attr->getMessage();
6737 const auto GetFunctionLevelDCIfCXXClass =
6745 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
6746 return MD->
getParent()->getCanonicalDecl();
6749 if (
const auto *RD = dyn_cast<CXXRecordDecl>(DC))
6750 return RD->getCanonicalDecl();
6757 const CXXRecordDecl *
const CurParentClass = GetFunctionLevelDCIfCXXClass(S);
6758 if (!CurParentClass)
6765 assert(NamingClass &&
"Must have naming class even for implicit access");
6771 return CurParentClass == NamingClass ||
6819 if (Call->getNumArgs() != 1)
6822 Expr *E = Call->getCallee()->IgnoreParenImpCasts();
6823 if (!E || isa<UnresolvedLookupExpr>(E))
6825 DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E);
6838 if (BuiltinID != Builtin::BImove && BuiltinID != Builtin::BIforward)
6841 S.
Diag(DRE->
getLocation(), diag::warn_unqualified_call_to_std_cast_function)
6852 if (Call.isInvalid())
6857 if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(Fn)) {
6858 if (ULE->hasExplicitTemplateArgs() &&
6859 ULE->decls_begin() == ULE->decls_end()) {
6861 ? diag::warn_cxx17_compat_adl_only_template_id
6862 : diag::ext_adl_only_template_id)
6871 CallExpr *CE = dyn_cast<CallExpr>(Call.get());
6883 Expr *ExecConfig,
bool IsExecConfig,
6884 bool AllowRecovery) {
6887 if (Result.isInvalid())
return ExprError();
6895 if (isa<CXXPseudoDestructorExpr>(Fn)) {
6896 if (!ArgExprs.empty()) {
6901 ArgExprs.back()->getEndLoc()));
6918 cast<CallExpr>(ExecConfig), ArgExprs,
6924 *
this, dyn_cast<UnresolvedMemberExpr>(Fn->
IgnoreParens()),
6945 RParenLoc, ExecConfig, IsExecConfig,
6962 Scope, Fn, ULE, LParenLoc, ArgExprs, RParenLoc, ExecConfig,
6965 RParenLoc, ExecConfig, IsExecConfig,
6979 bool CallingNDeclIndirectly =
false;
6981 if (
UnaryOperator *UnOp = dyn_cast<UnaryOperator>(NakedFn)) {
6982 if (UnOp->getOpcode() == UO_AddrOf) {
6983 CallingNDeclIndirectly =
true;
6988 if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
6989 NDecl = DRE->getDecl();
7002 nullptr, DRE->isNonOdrUse());
7005 }
else if (
auto *ME = dyn_cast<MemberExpr>(NakedFn))
7006 NDecl = ME->getMemberDecl();
7008 if (
FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(NDecl)) {
7022 FD->getBuiltinID()) {
7023 for (
unsigned Idx = 0; Idx < FD->param_size(); ++Idx) {
7026 !ArgExprs[Idx]->getType()->isPointerType())
7030 auto ArgTy = ArgExprs[Idx]->getType();
7031 auto ArgPtTy = ArgTy->getPointeeType();
7032 auto ArgAS = ArgPtTy.getAddressSpace();
7035 bool NeedImplicitASC =
7040 if (!NeedImplicitASC)
7044 if (ArgExprs[Idx]->isGLValue()) {
7046 Context, ArgExprs[Idx]->getType(), CK_NoOp, ArgExprs[Idx],
7051 Qualifiers ArgPtQuals = ArgPtTy.getQualifiers();
7061 CK_AddressSpaceConversion)
7071 llvm::any_of(ArgExprs,
7072 [](
clang::Expr *E) { return E->containsErrors(); })) &&
7073 "should only occur in error-recovery path.");
7075 llvm::isa_and_nonnull<FunctionDecl>(NDecl)
7076 ? cast<FunctionDecl>(NDecl)->getCallResultType()
7083 ExecConfig, IsExecConfig);
7096 assert(BuiltInDecl &&
"failed to find builtin declaration");
7100 assert(DeclRef.
isUsable() &&
"Builtin reference cannot fail");
7105 assert(!Call.isInvalid() &&
"Call to builtin cannot fail!");
7130 Diag(BuiltinLoc, diag::err_invalid_astype_of_different_size)
7159 FunctionDecl *FDecl = dyn_cast_or_null<FunctionDecl>(NDecl);
7160 unsigned BuiltinID = (FDecl ? FDecl->
getBuiltinID() : 0);
7163 if (FDecl && FDecl->
hasAttr<AnyX86InterruptAttr>()) {
7176 if (Caller->hasAttr<ARMInterruptAttr>()) {
7178 if (VFP && (!FDecl || !FDecl->
hasAttr<ARMInterruptAttr>())) {
7179 Diag(Fn->
getExprLoc(), diag::warn_arm_interrupt_calling_convention);
7184 if (Caller->hasAttr<AnyX86InterruptAttr>() &&
7185 ((!FDecl || !FDecl->
hasAttr<AnyX86NoCallerSavedRegistersAttr>()))) {
7210 if (Result.isInvalid())
7225 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7240 return ExprError(
Diag(LParenLoc, diag::err_typecheck_call_not_function)
7248 const auto *Proto = dyn_cast_or_null<FunctionProtoType>(FuncT);
7249 unsigned NumParams = Proto ? Proto->getNumParams() : 0;
7254 "CUDAKernelCallExpr should not use ADL");
7273 if (!Result.isUsable())
return ExprError();
7275 TheCall = dyn_cast<CallExpr>(Result.get());
7276 bool CorrectedTypos = TheCall != TheOldCall;
7277 if (!TheCall)
return Result;
7284 if (CorrectedTypos && Args.size() < NumParams) {
7300 return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7305 if (FDecl && !FDecl->
hasAttr<CUDAGlobalAttr>())
7306 return ExprError(
Diag(LParenLoc,diag::err_kern_call_not_global_function)
7313 return ExprError(
Diag(LParenLoc, diag::err_kern_type_not_void_return)
7317 if (FDecl && FDecl->
hasAttr<CUDAGlobalAttr>())
7318 return ExprError(
Diag(LParenLoc, diag::err_global_call_not_config)
7337 assert(isa<FunctionNoProtoType>(FuncT) &&
"Unknown FunctionType!");
7345 if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->
param_size()))
7346 Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
7366 if (!Proto && !Args.empty() &&
7370 Diag(LParenLoc, diag::warn_strict_uses_without_prototype)
7371 << (FDecl !=
nullptr) << FDecl;
7374 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7375 Expr *Arg = Args[i];
7377 if (Proto && i < Proto->getNumParams()) {
7379 Context, Proto->getParamType(i), Proto->isParamConsumed(i));
7397 diag::err_call_incomplete_argument, Arg))
7405 if (
CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
7406 if (!Method->isStatic())
7407 return ExprError(
Diag(LParenLoc, diag::err_member_call_without_object)
7416 for (
unsigned i = 0, e = Args.size(); i != e; i++) {
7417 if (
const auto *RT =
7418 dyn_cast<RecordType>(Args[i]->getType().getCanonicalType())) {
7419 if (RT->getDecl()->isOrContainsUnion())
7420 Diag(Args[i]->getBeginLoc(), diag::warn_cmse_nonsecure_union)
7428 if (CheckFunctionCall(FDecl, TheCall, Proto))
7431 checkFortifiedBuiltinMemoryFunction(FDecl, TheCall);
7434 return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall);
7436 if (CheckPointerCall(NDecl, TheCall, Proto))
7439 if (CheckOtherCall(TheCall, Proto))
7449 assert(Ty &&
"ActOnCompoundLiteral(): missing type");
7450 assert(InitExpr &&
"ActOnCompoundLiteral(): missing expression");
7468 diag::err_array_incomplete_or_sizeless_type,
7473 diag::err_variable_object_no_init)) {
7479 diag::err_typecheck_decl_incomplete_type,
7492 if (Result.isInvalid())
7494 LiteralExpr = Result.get();
7522 if (
auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
7523 for (
unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
7524 Expr *Init = ILE->getInit(i);
7529 VK, LiteralExpr, isFileScope);
7541 Diag(LParenLoc, diag::err_compound_literal_with_address_space)
7577 bool DiagnosedArrayDesignator =
false;
7578 bool DiagnosedNestedDesignator =
false;
7579 bool DiagnosedMixedDesignator =
false;
7583 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7584 if (
auto *DIE = dyn_cast<DesignatedInitExpr>(InitArgList[I])) {
7586 FirstDesignator = DIE->getBeginLoc();
7591 if (!DiagnosedNestedDesignator && DIE->size() > 1) {
7592 DiagnosedNestedDesignator =
true;
7593 Diag(DIE->getBeginLoc(), diag::ext_designated_init_nested)
7594 << DIE->getDesignatorsSourceRange();
7597 for (
auto &Desig : DIE->designators()) {
7598 if (!Desig.isFieldDesignator() && !DiagnosedArrayDesignator) {
7599 DiagnosedArrayDesignator =
true;
7600 Diag(Desig.getBeginLoc(), diag::ext_designated_init_array)
7601 << Desig.getSourceRange();
7605 if (!DiagnosedMixedDesignator &&
7606 !isa<DesignatedInitExpr>(InitArgList[0])) {
7607 DiagnosedMixedDesignator =
true;
7608 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7609 << DIE->getSourceRange();
7610 Diag(InitArgList[0]->getBeginLoc(), diag::note_designated_init_mixed)
7611 << InitArgList[0]->getSourceRange();
7614 isa<DesignatedInitExpr>(InitArgList[0])) {
7615 DiagnosedMixedDesignator =
true;
7616 auto *DIE = cast<DesignatedInitExpr>(InitArgList[0]);
7617 Diag(DIE->getBeginLoc(), diag::ext_designated_init_mixed)
7618 << DIE->getSourceRange();
7619 Diag(InitArgList[I]->getBeginLoc(), diag::note_designated_init_mixed)
7620 << InitArgList[I]->getSourceRange();
7624 if (FirstDesignator.
isValid()) {
7628 !DiagnosedNestedDesignator && !DiagnosedMixedDesignator) {
7630 ? diag::warn_cxx17_compat_designated_init
7631 : diag::ext_cxx_designated_init);
7633 Diag(FirstDesignator, diag::ext_designated_init);
7648 for (
unsigned I = 0, E = InitArgList.size(); I != E; ++I) {
7649 if (InitArgList[I]->getType()->isNonOverloadPlaceholderType()) {
7656 InitArgList[I] = result.
get();
7684 if (
type->isObjCObjectPointerType()) {
7686 }
else if (
type->isBlockPointerType()) {
7688 return CK_BlockPointerToObjCPointerCast;
7690 assert(
type->isPointerType());
7691 return CK_CPointerToObjCPointerCast;
7708 llvm_unreachable(
"member pointer type in C");
7717 if (SrcAS != DestAS)
7718 return CK_AddressSpaceConversion;
7725 ? CK_BitCast : CK_AnyPointerToBlockPointerCast);
7730 return CK_CPointerToObjCPointerCast;
7732 return CK_BlockPointerToObjCPointerCast;
7734 return CK_PointerToBoolean;
7736 return CK_PointerToIntegral;
7742 llvm_unreachable(
"illegal cast from pointer");
7744 llvm_unreachable(
"Should have returned before this");
7749 return CK_FixedPointCast;
7751 return CK_FixedPointToBoolean;
7753 return CK_FixedPointToIntegral;
7755 return CK_FixedPointToFloating;
7759 diag::err_unimplemented_conversion_with_fixed_point_type)
7761 return CK_IntegralCast;
7766 llvm_unreachable(
"illegal cast to pointer type");
7768 llvm_unreachable(
"Should have returned before this");
7778 return CK_NullToPointer;
7779 return CK_IntegralToPointer;
7781 return CK_IntegralToBoolean;
7783 return CK_IntegralCast;
7785 return CK_IntegralToFloating;
7790 return CK_IntegralRealToComplex;
7794 CK_IntegralToFloating);
7795 return CK_FloatingRealToComplex;
7797 llvm_unreachable(
"member pointer type in C");
7799 return CK_IntegralToFixedPoint;
7801 llvm_unreachable(
"Should have returned before this");
7806 return CK_FloatingCast;
7808 return CK_FloatingToBoolean;
7810 return CK_FloatingToIntegral;
7815 return CK_FloatingRealToComplex;
7819 CK_FloatingToIntegral);
7820 return CK_IntegralRealToComplex;
7824 llvm_unreachable(
"valid float->pointer cast?");
7826 llvm_unreachable(
"member pointer type in C");
7828 return CK_FloatingToFixedPoint;
7830 llvm_unreachable(
"Should have returned before this");
7835 return CK_FloatingComplexCast;
7837 return CK_FloatingComplexToIntegralComplex;
7841 return CK_FloatingComplexToReal;
7843 return CK_FloatingCast;
7846 return CK_FloatingComplexToBoolean;
7850 CK_FloatingComplexToReal);
7851 return CK_FloatingToIntegral;
7855 llvm_unreachable(
"valid complex float->pointer cast?");
7857 llvm_unreachable(
"member pointer type in C");
7860 diag::err_unimplemented_conversion_with_fixed_point_type)
7862 return CK_IntegralCast;
7864 llvm_unreachable(
"Should have returned before this");
7869 return CK_IntegralComplexToFloatingComplex;
7871 return CK_IntegralComplexCast;
7875 return CK_IntegralComplexToReal;
7877 return CK_IntegralCast;
7880 return CK_IntegralComplexToBoolean;
7884 CK_IntegralComplexToReal);
7885 return CK_IntegralToFloating;
7889 llvm_unreachable(
"valid complex int->pointer cast?");
7891 llvm_unreachable(
"member pointer type in C");
7894 diag::err_unimplemented_conversion_with_fixed_point_type)
7896 return CK_IntegralCast;
7898 llvm_unreachable(
"Should have returned before this");
7901 llvm_unreachable(
"Unhandled scalar cast");
7908 len = vecType->getNumElements();
7909 eltType = vecType->getElementType();
7916 if (!
type->isRealType())
return false;
7932 auto ValidScalableConversion = [](
QualType FirstType,
QualType SecondType) {
7936 const auto *VecTy = SecondType->getAs<
VectorType>();
7941 return ValidScalableConversion(srcTy, destTy) ||
7942 ValidScalableConversion(destTy, srcTy);
7954 return matSrcType->
getNumRows() == matDestType->getNumRows() &&
7955 matSrcType->
getNumColumns() == matDestType->getNumColumns();
7974 return (SrcLen * SrcEltSize == DestLen * DestEltSize);
7980 "expected at least one type to be a vector here");
7982 bool IsSrcTyAltivec =
7989 return (IsSrcTyAltivec || IsDestTyAltivec);
7995 "expected at least one type to be a vector here");
8004 return (SrcEltTy == DestEltTy);
8040 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
8045 if (!Vec || !Vec->getElementType()->isIntegralOrEnumerationType())
8062 return Diag(R.
getBegin(), diag::err_invalid_conversion_between_matrixes)
8063 << DestTy << SrcTy << R;
8067 diag::err_invalid_conversion_between_matrix_and_type)
8068 << SrcTy << DestTy << R;
8071 diag::err_invalid_conversion_between_matrix_and_type)
8072 << DestTy << SrcTy << R;
8075 Kind = CK_MatrixCast;
8081 assert(VectorTy->
isVectorType() &&
"Not a vector type!");
8087 diag::err_invalid_conversion_between_vectors :
8088 diag::err_invalid_conversion_between_vector_and_integer)
8089 << VectorTy << Ty << R;
8092 diag::err_invalid_conversion_between_vector_and_scalar)
8093 << VectorTy << Ty << R;
8102 if (DestElemTy == SplattedExpr->
getType())
8103 return SplattedExpr;
8116 CK_BooleanToSignedIntegral);
8117 SplattedExpr = CastExprRes.
get();
8118 CK = CK_IntegralToFloating;
8120 CK = CK_BooleanToSignedIntegral;
8127 SplattedExpr = CastExprRes.
get();
8146 Diag(R.
getBegin(),diag::err_invalid_conversion_between_ext_vectors)
8147 << DestTy << SrcTy << R;
8159 diag::err_invalid_conversion_between_vector_and_scalar)
8160 << DestTy << SrcTy << R;
8162 Kind = CK_VectorSplat;
8171 "ActOnCastExpr(): missing type or expr");
8193 bool isVectorLiteral =
false;
8208 isVectorLiteral =
true;
8211 isVectorLiteral =
true;
8216 if (isVectorLiteral)
8222 if (isa<ParenListExpr>(
CastExpr)) {
8224 if (Result.isInvalid())
return ExprError();
8243 assert((isa<ParenListExpr>(E) || isa<ParenExpr>(E)) &&
8244 "Expected paren or paren list expression");
8251 LiteralLParenLoc = PE->getLParenLoc();
8252 LiteralRParenLoc = PE->getRParenLoc();
8253 exprs = PE->getExprs();
8254 numExprs = PE->getNumExprs();
8256 LiteralLParenLoc = cast<ParenExpr>(E)->getLParen();
8257 LiteralRParenLoc = cast<ParenExpr>(E)->getRParen();
8258 subExpr = cast<ParenExpr>(E)->getSubExpr();
8281 if (numExprs == 1) {
8290 else if (numExprs < numElems) {
8292 diag::err_incorrect_number_of_vector_initializers);
8296 initExprs.append(exprs, exprs + numExprs);
8313 initExprs.append(exprs, exprs + numExprs);
8318 initExprs, LiteralRParenLoc);
8333 for (
unsigned i = 1, e = E->
getNumExprs(); i != e && !Result.isInvalid(); ++i)
8337 if (Result.isInvalid())
return ExprError();
8353 Expr *NullExpr = LHSExpr;
8354 Expr *NonPointerExpr = RHSExpr;
8361 NonPointerExpr = LHSExpr;
8383 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands_null)
8384 << NonPointerExpr->
getType() << DiagType
8395 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8403 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar)
8437 bool IsBlockPointer =
false;
8441 IsBlockPointer =
true;
8466 ResultAddrSpace = LAddrSpace;
8468 ResultAddrSpace = RAddrSpace;
8470 S.
Diag(Loc, diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
8477 auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast;
8492 LAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8494 RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
8502 lhptee, rhptee,
false,
false,
8505 if (CompositeTy.
isNull()) {
8522 S.
Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
8533 QualType ResultTy = [&, ResultAddrSpace]() {
8539 .withCVRQualifiers(MergedCVRQual);
8568 S.
Diag(Loc, diag::err_typecheck_cond_incompatible_operands)
8621 bool IsIntFirstExpr) {
8626 Expr *Expr1 = IsIntFirstExpr ? Int.
get() : PointerExpr;
8627 Expr *Expr2 = IsIntFirstExpr ? PointerExpr : Int.
get();
8629 S.
Diag(Loc, diag::ext_typecheck_cond_pointer_integer_mismatch)
8633 CK_IntegralToPointer);
8667 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8673 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float)
8679 if (LHSType == RHSType)
8688 return handleIntegerConversion<doIntegralCast, doIntegralCast>
8689 (S, LHS, RHS, LHSType, RHSType,
false);
8723 llvm::raw_svector_ostream OS(Str);
8724 OS <<
"(vector of " << NumElements <<
" '" << EleTyName <<
"' values)";
8725 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8726 << CondTy << OS.str();
8747 S.
Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat)
8765 S.
Diag(QuestionLoc, diag::err_conditional_vector_size)
8766 << CondTy << VecResTy;
8771 QualType RVE = RV->getElementType();
8774 S.
Diag(QuestionLoc, diag::err_conditional_vector_element_size)
8775 << CondTy << VecResTy;
8801 bool IsBoolVecLang =
8825 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
8826 QualType Ty = CE->getCallee()->getType();
8864 "should only occur in error-recovery path.");
8902 diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy
8921 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
8942 if (LHSRT->getDecl() == RHSRT->getDecl())
8986 if (!compositeType.
isNull())
8987 return compositeType;
9021 Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
9093 if (!(compositeType =
9101 RHSOPT->isObjCQualifiedIdType()) &&
9112 Diag(QuestionLoc, diag::ext_typecheck_cond_incompatible_operands)
9123 return compositeType;
9130 Diag(QuestionLoc, diag::err_cond_voidptr_arc) << LHSTy << RHSTy
9150 Diag(QuestionLoc, diag::err_cond_voidptr_arc) << LHSTy << RHSTy
9177 Self.
Diag(Loc, Note)
9182 Self.
Diag(Loc, Note) << ParenRange;
9207 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
9208 E = MTE->getSubExpr();
9215 *
Opcode = OP->getOpcode();
9216 *RHSExprs = OP->getRHS();
9223 if (Call->getNumArgs() != 2)
9229 if (OO < OO_Plus || OO > OO_Arrow ||
9230 OO == OO_PlusPlus || OO == OO_MinusMinus)
9236 *RHSExprs = Call->getArg(1);
9253 return OP->isComparisonOp() || OP->isLogicalOp();
9255 return OP->getOpcode() == UO_LNot;
9285 ? diag::warn_precedence_bitwise_conditional
9286 : diag::warn_precedence_conditional;
9288 Self.
Diag(OpLoc, DiagID)
9294 Self.
PDiag(diag::note_precedence_silence)
9299 Self.
PDiag(diag::note_precedence_conditional_first),
9310 auto GetNullability = [](
QualType Ty) {
9311 std::optional<NullabilityKind>
Kind = Ty->getNullability();
9321 auto LHSKind = GetNullability(LHSTy), RHSKind = GetNullability(RHSTy);
9329 MergedKind = RHSKind;
9336 MergedKind = RHSKind;
9338 MergedKind = LHSKind;
9344 if (GetNullability(ResTy) == MergedKind)
9381 CondExpr = CondResult.
get();
9382 LHSExpr = LHSResult.
get();
9383 RHSExpr = RHSResult.
get();
9389 Expr *commonExpr =
nullptr;
9391 commonExpr = CondExpr;
9398 commonExpr = result.
get();
9412 commonExpr = commonRes.
get();
9422 commonExpr = MatExpr.
get();
9430 LHSExpr = CondExpr = opaqueValue;
9436 ExprResult Cond = CondExpr, LHS = LHSExpr, RHS = RHSExpr;
9438 VK, OK, QuestionLoc);
9446 CheckBoolLikeConversion(Cond.
get(), QuestionLoc);
9454 RHS.get(), result, VK, OK);
9457 commonExpr, opaqueValue, Cond.
get(), LHS.get(), RHS.get(), QuestionLoc,
9458 ColonLoc, result, VK, OK);
9466 if (
const auto *ToFn =
9468 if (
const auto *FromFn =
9487 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9488 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9491 const Type *lhptee, *rhptee;
9493 std::tie(lhptee, lhq) =
9494 cast<PointerType>(LHSType)->getPointeeType().split().asPair();
9495 std::tie(rhptee, rhq) =
9496 cast<PointerType>(RHSType)->getPointeeType().split().asPair();
9556 diag::warn_typecheck_convert_incompatible_function_pointer_strict,
9579 if (ltrans == rtrans) {
9593 if (isa<PointerType>(lhptee) && isa<PointerType>(rhptee)) {
9595 std::tie(lhptee, lhq) =
9596 cast<PointerType>(lhptee)->getPointeeType().split().asPair();
9597 std::tie(rhptee, rhq) =
9598 cast<PointerType>(rhptee)->getPointeeType().split().asPair();
9611 }
while (isa<PointerType>(lhptee) && isa<PointerType>(rhptee));
9613 if (lhptee == rhptee)
9637 assert(LHSType.
isCanonical() &&
"LHS not canonicalized!");
9638 assert(RHSType.
isCanonical() &&
"RHS not canonicalized!");
9659 if (LQuals != RQuals)
9688 assert(LHSType.
isCanonical() &&
"LHS was not canonicalized!");
9689 assert(RHSType.
isCanonical() &&
"RHS was not canonicalized!");
9737 return VT->getElementType().getCanonicalType() == ElementType;
9770 if (LHSType == RHSType) {
9777 if (
const auto *AT = dyn_cast<AutoType>(LHSType)) {
9778 if (AT->isGNUAutoType()) {
9786 if (
const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
9791 if (
Kind != CK_NoOp && ConvertRHS)
9793 Kind = CK_NonAtomicToAtomic;
9806 Kind = CK_LValueBitCast;
9821 Kind = CK_VectorSplat;
9846 << RHSType << LHSType;
9862 << RHSType << LHSType;
9902 if (
const PointerType *LHSPointer = dyn_cast<PointerType>(LHSType)) {
9904 if (isa<PointerType>(RHSType)) {
9905 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9907 if (AddrSpaceL != AddrSpaceR)
9908 Kind = CK_AddressSpaceConversion;
9919 Kind = CK_IntegralToPointer;
9925 if (isa<ObjCObjectPointerType>(RHSType)) {
9927 if (LHSPointer->getPointeeType()->isVoidType()) {
9946 if (LHSPointer->getPointeeType()->isVoidType()) {
9947 LangAS AddrSpaceL = LHSPointer->getPointeeType().getAddressSpace();
9952 AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9961 if (isa<BlockPointerType>(LHSType)) {
9970 Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
9976 Kind = CK_IntegralToPointer;
9982 Kind = CK_AnyPointerToBlockPointerCast;
9988 if (RHSPT->getPointeeType()->isVoidType()) {
9989 Kind = CK_AnyPointerToBlockPointerCast;
9997 if (isa<ObjCObjectPointerType>(LHSType)) {
10003 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10012 Kind = CK_IntegralToPointer;
10018 if (isa<PointerType>(RHSType)) {
10019 Kind = CK_CPointerToObjCPointerCast;
10041 Kind = CK_BlockPointerToObjCPointerCast;
10049 if (isa<PointerType>(RHSType)) {
10052 Kind = CK_PointerToBoolean;
10058 Kind = CK_PointerToIntegral;
10066 if (isa<ObjCObjectPointerType>(RHSType)) {
10069 Kind = CK_PointerToBoolean;
10075 Kind = CK_PointerToIntegral;
10083 if (isa<TagType>(LHSType) && isa<TagType>(RHSType)) {
10091 Kind = CK_IntToOCLSampler;
10113 TypeSourceInfo *unionTInfo = C.getTrivialTypeSourceInfo(UnionType);
10133 for (
auto *it : UD->
fields()) {
10134 if (it->getType()->isPointerType()) {
10173 bool DiagnoseCFAudited,
10177 assert((ConvertRHS || !Diagnose) &&
"can't indicate whether we diagnosed");
10183 ExprResult &RHS = ConvertRHS ? CallerRHS : LocalRHS;
10187 if (RHSPtrType->getPointeeType()->hasAttr(attr::NoDeref) &&
10188 !LHSPtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
10190 diag::warn_noderef_to_dereferenceable_pointer)
10221 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10236 RHS.
get(), LHSType,
false, DAP))
10266 if (Diagnose || ConvertRHS) {
10301 if (
getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
10303 Diagnose, DiagnoseCFAudited) !=
ACR_okay) {
10309 E->
getType(), E, Diagnose) ||
10330 struct OriginalOperand {
10331 explicit OriginalOperand(
Expr *Op) : Orig(Op), Conversion(nullptr) {
10332 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Op))
10333 Op = MTE->getSubExpr();
10334 if (
auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Op))
10335 Op = BTE->getSubExpr();
10336 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(Op)) {
10337 Orig = ICE->getSubExprAsWritten();
10338 Conversion = ICE->getConversionFunction();
10342 QualType getType()
const {
return Orig->getType(); }
10351 OriginalOperand OrigLHS(LHS.
get()), OrigRHS(RHS.
get());
10353 Diag(Loc, diag::err_typecheck_invalid_operands)
10354 << OrigLHS.getType() << OrigRHS.getType()
10359 if (OrigLHS.Conversion) {
10360 Diag(OrigLHS.Conversion->getLocation(),
10361 diag::note_typecheck_invalid_operands_converted)
10364 if (OrigRHS.Conversion) {
10365 Diag(OrigRHS.Conversion->getLocation(),
10366 diag::note_typecheck_invalid_operands_converted)
10384 if (!(LHSNatVec && RHSNatVec)) {
10385 Expr *Vector = LHSNatVec ? LHS.
get() : RHS.
get();
10386 Expr *NonVector = !LHSNatVec ? LHS.
get() : RHS.
get();
10387 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10389 << Vector->getSourceRange();
10393 Diag(Loc, diag::err_typecheck_logical_vector_expr_gnu_cpp_restrict)
10416 unsigned &DiagID) {
10425 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10430 scalarCast = CK_IntegralCast;
10435 DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type;
10438 scalarCast = CK_FloatingCast;
10441 scalarCast = CK_IntegralToFloating;
10450 if (scalarCast != CK_NoOp)
10461 assert(VecTy &&
"Expression E must be a vector");
10466 VecTy->getVectorKind());
10470 if (
auto *ICE = dyn_cast<ImplicitCastExpr>(E))
10471 if (ICE->getSubExpr()->getType() == NewVecTy)
10472 return ICE->getSubExpr();
10497 unsigned NumBits = IntSigned
10498 ? (Result.isNegative() ? Result.getMinSignedBits()
10499 : Result.getActiveBits())
10500 : Result.getActiveBits();
10507 return (IntSigned != OtherIntSigned &&
10513 return (Order < 0);
10537 llvm::APFloat::rmTowardZero);
10540 bool Ignored =
false;
10541 Float.convertToInteger(ConvertBack, llvm::APFloat::rmNearestTiesToEven,
10543 if (Result != ConvertBack)
10549 unsigned FloatPrec = llvm::APFloat::semanticsPrecision(
10551 if (Bits > FloatPrec)
10564 QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
10565 QualType VectorTy = Vector->get()->getType().getUnqualifiedType();
10569 assert(!isa<ExtVectorType>(VT) &&
10570 "ExtVectorTypes should not be handled here!");
10571 VectorEltTy = VT->getElementType();
10576 llvm_unreachable(
"Only Fixed-Length and SVE Vector types are handled here");
10602 ScalarCast = CK_IntegralCast;
10606 ScalarCast = CK_FloatingToIntegral;
10620 bool CstScalar = Scalar->get()->isValueDependent() ||
10621 Scalar->get()->EvaluateAsFloat(Result, S.
Context);
10623 if (!CstScalar && Order < 0)
10629 bool Truncated =
false;
10631 llvm::APFloat::rmNearestTiesToEven, &Truncated);
10636 ScalarCast = CK_FloatingCast;
10641 ScalarCast = CK_IntegralToFloating;
10649 if (ScalarCast != CK_NoOp)
10658 bool AllowBothBool,
10659 bool AllowBoolConversions,
10660 bool AllowBoolOperation,
10661 bool ReportInvalid) {
10662 if (!IsCompAssign) {
10678 assert(LHSVecType || RHSVecType);
10681 (RHSVecType && RHSVecType->getElementType()->isBFloat16Type()))
10686 if (!AllowBothBool &&
10692 if (!AllowBoolOperation &&
10701 if (LHSVecType && RHSVecType &&
10703 if (isa<ExtVectorType>(LHSVecType)) {
10716 if (AllowBoolConversions && LHSVecType && RHSVecType &&
10726 if (!IsCompAssign &&
10729 RHSVecType->getElementType()->isIntegerType()) {
10745 if (IsSveConversion(LHSType, RHSType) || IsSveConversion(RHSType, LHSType)) {
10746 Diag(Loc, diag::err_typecheck_sve_ambiguous) << LHSType << RHSType;
10756 if (FirstVecType && SecondVecType)
10758 (SecondVecType->getVectorKind() ==
10760 SecondVecType->getVectorKind() ==
10767 if (IsSveGnuConversion(LHSType, RHSType) ||
10768 IsSveGnuConversion(RHSType, LHSType)) {
10769 Diag(Loc, diag::err_typecheck_sve_gnu_ambiguous) << LHSType << RHSType;
10775 unsigned DiagID = diag::err_typecheck_vector_not_convertable;
10777 if (isa<ExtVectorType>(LHSVecType)) {
10788 if (isa<ExtVectorType>(RHSVecType)) {
10790 LHSType, RHSVecType->getElementType(),
10803 QualType VecType = LHSVecType ? LHSType : RHSType;
10804 const VectorType *VT = LHSVecType ? LHSVecType : RHSVecType;
10805 QualType OtherType = LHSVecType ? RHSType : LHSType;
10806 ExprResult *OtherExpr = LHSVecType ? &RHS : &LHS;
10810 Diag(Loc, diag::warn_deprecated_lax_vec_conv_all) << RHSType << LHSType;
10814 if (!IsCompAssign) {
10833 if ((!RHSVecType && !RHSType->
isRealType()) ||
10835 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10836 << LHSType << RHSType
10846 RHSVecType && isa<ExtVectorType>(RHSVecType) &&
10847 LHSVecType && isa<ExtVectorType>(LHSVecType)) {
10848 Diag(Loc, diag::err_opencl_implicit_vector_conversion) << LHSType
10857 if ((RHSVecType && !isa<ExtVectorType>(RHSVecType)) ||
10858 (LHSVecType && !isa<ExtVectorType>(LHSVecType))) {
10859 QualType Scalar = LHSVecType ? RHSType : LHSType;
10860 QualType Vector = LHSVecType ? LHSType : RHSType;
10861 unsigned ScalarOrVector = LHSVecType && RHSVecType ? 1 : 0;
10863 diag::err_typecheck_vector_not_convertable_implict_truncation)
10864 << ScalarOrVector << Scalar << Vector;
10871 << LHSType << RHSType
10880 if (!IsCompAssign) {
10895 unsigned DiagID = diag::err_typecheck_invalid_operands;
10897 ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
10898 (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
10919 Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10928 Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
10937 bool ScalarOrVector =
10940 Diag(Loc, diag::err_typecheck_vector_not_convertable_implict_truncation)
10941 << ScalarOrVector << Scalar << Vector;
10973 S.
Diag(Loc, diag::warn_null_in_arithmetic_operation)
10985 S.
Diag(Loc, diag::warn_null_in_comparison_operation)
10986 << LHSNull << NonNullType
10992 const auto *LUE = dyn_cast<UnaryExprOrTypeTraitExpr>(LHS);
10993 const auto *RUE = dyn_cast<UnaryExprOrTypeTraitExpr>(RHS);
10996 if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() ||
10997 RUE->getKind() != UETT_SizeOf)
11004 if (RUE->isArgumentType())
11005 RHSTy = RUE->getArgumentType().getNonReferenceType();
11007 RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
11014 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11015 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11016 S.
Diag(LHSArgDecl->getLocation(), diag::note_pointer_declared_here)
11020 QualType ArrayElemTy = ArrayTy->getElementType();
11026 S.
Diag(Loc, diag::warn_division_sizeof_array)
11028 if (
const auto *DRE = dyn_cast<DeclRefExpr>(LHSArg)) {
11029 if (
const ValueDecl *LHSArgDecl = DRE->getDecl())
11030 S.
Diag(LHSArgDecl->getLocation(), diag::note_array_declared_here)
11034 S.
Diag(Loc, diag::note_precedence_silence) << RHS;
11047 S.
PDiag(diag::warn_remainder_division_by_zero)
11053 bool IsCompAssign,
bool IsDiv) {
11131 ? diag::err_typecheck_pointer_arith_void_type
11132 : diag::ext_gnu_void_ptr)
11141 ? diag::err_typecheck_pointer_arith_void_type
11142 : diag::ext_gnu_void_ptr)
11143 << 0 << Pointer->getSourceRange();
11152 Expr *Pointer,
bool IsGNUIdiom) {
11154 S.
Diag(Loc, diag::warn_gnu_null_ptr_arith)
11155 << Pointer->getSourceRange();
11157 S.
Diag(Loc, diag::warn_pointer_arith_null_ptr)
11158 << S.
getLangOpts().CPlusPlus << Pointer->getSourceRange();
11164 Expr *Pointer,
bool BothNull) {
11174 S.
PDiag(diag::warn_pointer_sub_null_ptr)
11176 << Pointer->getSourceRange());
11185 ? diag::err_typecheck_pointer_arith_function_type
11186 : diag::ext_gnu_ptr_func_arith)
11198 assert(Pointer->getType()->isAnyPointerType());
11200 ? diag::err_typecheck_pointer_arith_function_type
11201 : diag::ext_gnu_ptr_func_arith)
11202 << 0 << Pointer->getType()->getPointeeType()
11204 << Pointer->getSourceRange();
11212 QualType ResType = Operand->getType();
11214 ResType = ResAtomicType->getValueType();
11220 diag::err_typecheck_arithmetic_incomplete_or_sizeless_type,
11221 Operand->getSourceRange());
11234 QualType ResType = Operand->getType();
11236 ResType = ResAtomicType->getValueType();
11268 if (!isLHSPointer && !isRHSPointer)
return true;
11270 QualType LHSPointeeTy, RHSPointeeTy;
11275 if (isLHSPointer && isRHSPointer) {
11278 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
11286 bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->
isVoidType();
11287 bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->
isVoidType();
11288 if (isLHSVoidPtr || isRHSVoidPtr) {
11296 bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->
isFunctionType();
11297 bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->
isFunctionType();
11298 if (isLHSFuncPtr || isRHSFuncPtr) {
11320 Expr* IndexExpr = RHSExpr;
11323 IndexExpr = LHSExpr;
11326 bool IsStringPlusInt = StrExpr &&
11332 Self.
Diag(OpLoc, diag::warn_string_plus_int)
11336 if (IndexExpr == RHSExpr) {
11338 Self.
Diag(OpLoc, diag::note_string_plus_scalar_silence)
11343 Self.
Diag(OpLoc, diag::note_string_plus_scalar_silence);
11349 const Expr *StringRefExpr = LHSExpr;
11354 CharExpr = dyn_cast<CharacterLiteral>(LHSExpr->
IgnoreImpCasts());
11355 StringRefExpr = RHSExpr;
11358 if (!CharExpr || !StringRefExpr)
11378 Self.
Diag(OpLoc, diag::warn_string_plus_char)
11379 << DiagRange << Ctx.
CharTy;
11381 Self.
Diag(OpLoc, diag::warn_string_plus_char)
11382 << DiagRange << CharExpr->
getType();
11388 Self.
Diag(OpLoc, diag::note_string_plus_scalar_silence)
11393 Self.
Diag(OpLoc, diag::note_string_plus_scalar_silence);
11402 S.
Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
11421 if (CompLHSTy) *CompLHSTy = compType;
11430 *CompLHSTy = compType;
11439 *CompLHSTy = compType;
11449 if (Opc == BO_Add) {
11456 if (CompLHSTy) *CompLHSTy = compType;
11470 std::swap(PExp, IExp);
11481 if (!IExp->getType()->isIntegerType())
11490 (!IExp->isValueDependent() &&
11491 (!IExp->EvaluateAsInt(KnownVal,
Context) ||
11495 Context, BO_Add, PExp, IExp);
11507 CheckArrayAccess(PExp, IExp);
11516 *CompLHSTy = LHSTy;
11536 if (CompLHSTy) *CompLHSTy = compType;
11545 *CompLHSTy = compType;
11554 *CompLHSTy = compType;
11567 if (CompLHSTy) *CompLHSTy = compType;
11601 CheckArrayAccess(LHS.
get(), RHS.
get(),
nullptr,
11604 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11648 if (ElementSize.
isZero()) {
11649 Diag(Loc,diag::warn_sub_ptr_zero_size_types)
11655 if (CompLHSTy) *CompLHSTy = LHS.
get()->
getType();
11665 return ET->getDecl()->isScoped();
11684 if (Right.isNegative()) {
11686 S.
PDiag(diag::warn_shift_negative)
11697 LeftSize = FXSema.getWidth() - (
unsigned)FXSema.hasUnsignedPadding();
11699 llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
11700 if (Right.uge(LeftBits)) {
11702 S.
PDiag(diag::warn_shift_gt_typewidth)
11733 if (Left.isNegative()) {
11735 S.
PDiag(diag::warn_shift_lhs_negative)
11741 static_cast<llvm::APInt&
>(Right) + Left.getMinSignedBits();
11742 if (LeftBits.uge(ResultBits))
11744 llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
11745 Result = Result.shl(Right);
11750 Result.toString(HexResult, 16,
false,
true);
11756 if (LeftBits == ResultBits - 1) {
11757 S.
Diag(Loc, diag::warn_shift_result_sets_sign_bit)
11758 << HexResult << LHSType
11763 S.
Diag(Loc, diag::warn_shift_result_gt_typewidth)
11764 << HexResult.str() << Result.getMinSignedBits() << LHSType
11776 S.
Diag(Loc, diag::err_shift_rhs_only_vector)
11782 if (!IsCompAssign) {
11804 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
11811 if (!LHSEleType->isIntegerType()) {
11812 S.
Diag(Loc, diag::err_typecheck_expect_int)
11817 if (!RHSEleType->isIntegerType()) {
11818 S.
Diag(Loc, diag::err_typecheck_expect_int)
11827 if (LHSEleType != RHSEleType) {
11829 LHSEleType = RHSEleType;
11835 }
else if (RHSVecTy) {
11840 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
11848 if (LHSBT != RHSBT &&
11850 S.
Diag(Loc, diag::warn_typecheck_vector_element_sizes_not_equal)
11867 bool IsCompAssign) {
11868 if (!IsCompAssign) {
11891 if ((LHSBuiltinTy && LHSBuiltinTy->
isSVEBool()) ||
11892 (RHSBuiltinTy && RHSBuiltinTy->
isSVEBool())) {
11893 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
11898 if (!LHSEleType->isIntegerType()) {
11899 S.
Diag(Loc, diag::err_typecheck_expect_int)
11904 if (!RHSEleType->isIntegerType()) {
11905 S.
Diag(Loc, diag::err_typecheck_expect_int)
11913 S.
Diag(Loc, diag::err_typecheck_invalid_operands)
11923 if (LHSEleType != RHSEleType) {
11925 LHSEleType = RHSEleType;
11927 const llvm::ElementCount VecSize =
11936 S.
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
11942 const llvm::ElementCount VecSize =
11944 if (LHSEleType != RHSEleType) {
11946 RHSEleType = LHSEleType;
11959 bool IsCompAssign) {
11993 if (IsCompAssign) LHS = OldLHS;
12024 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_distinct_pointers
12025 : diag::ext_typecheck_comparison_of_distinct_pointers)
12065 S.
Diag(Loc, IsError ? diag::err_typecheck_comparison_of_fptr_to_void
12066 : diag::ext_typecheck_comparison_of_fptr_to_void)
12073 case Stmt::ObjCArrayLiteralClass:
12074 case Stmt::ObjCDictionaryLiteralClass:
12075 case Stmt::ObjCStringLiteralClass:
12076 case Stmt::ObjCBoxedExprClass:
12135 case Stmt::ObjCStringLiteralClass:
12138 case Stmt::ObjCArrayLiteralClass:
12141 case Stmt::ObjCDictionaryLiteralClass:
12144 case Stmt::BlockExprClass:
12146 case Stmt::ObjCBoxedExprClass: {
12147 Expr *Inner = cast<ObjCBoxedExpr>(FromE)->getSubExpr()->IgnoreParens();
12148 switch (Inner->getStmtClass()) {
12149 case Stmt::IntegerLiteralClass:
12150 case Stmt::FloatingLiteralClass:
12151 case Stmt::CharacterLiteralClass:
12152 case Stmt::ObjCBoolLiteralExprClass:
12153 case Stmt::CXXBoolLiteralExprClass:
12156 case Stmt::ImplicitCastExprClass: {
12157 CastKind CK = cast<CastExpr>(Inner)->getCastKind();
12159 if (CK == CK_IntegralToBoolean || CK == CK_IntegralCast)
12186 Other = Other->IgnoreParenCasts();
12197 llvm_unreachable(
"Unknown Objective-C object literal kind");
12201 S.
Diag(Loc, diag::warn_objc_string_literal_comparison)
12202 <<
Literal->getSourceRange();
12204 S.
Diag(Loc, diag::warn_objc_literal_comparison)
12205 << LiteralKind <<
Literal->getSourceRange();
12214 S.
Diag(Loc, diag::note_objc_literal_comparison_isequal)
12227 if (!UO || UO->
getOpcode() != UO_LNot)
return;
12237 bool IsBitwiseOp = Opc == BO_And || Opc == BO_Or || Opc == BO_Xor;
12239 << Loc << IsBitwiseOp;
12266 if (
const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
12268 }
else if (
const MemberExpr *Mem = dyn_cast<MemberExpr>(E)) {
12269 if (Mem->isImplicitAccess())
12270 D = Mem->getMemberDecl();
12320 S.
Diag(Loc, diag::warn_depr_array_comparison)
12335 Result = AlwaysTrue;
12340 Result = AlwaysFalse;
12343 Result = AlwaysEqual;
12346 Result = AlwaysConstant;
12350 S.
PDiag(diag::warn_comparison_always)
12358 Result = AlwaysFalse;
12361 Result = AlwaysTrue;
12365 Result = AlwaysConstant;
12369 S.
PDiag(diag::warn_comparison_always)
12375 if (isa<CastExpr>(LHSStripped))
12377 if (isa<CastExpr>(RHSStripped))
12382 Expr *LiteralString =
nullptr;
12383 Expr *LiteralStringStripped =
nullptr;
12384 if ((isa<StringLiteral>(LHSStripped) || isa<ObjCEncodeExpr>(LHSStripped)) &&
12387 LiteralString = LHS;
12388 LiteralStringStripped = LHSStripped;
12389 }
else if ((isa<StringLiteral>(RHSStripped) ||
12390 isa<ObjCEncodeExpr>(RHSStripped)) &&
12393 LiteralString = RHS;
12394 LiteralStringStripped = RHSStripped;
12397 if (LiteralString) {
12399 S.
PDiag(diag::warn_stringcompare)
12400 << isa<ObjCEncodeExpr>(LiteralStringStripped)
12412 llvm_unreachable(
"unhandled cast kind");
12414 case CK_UserDefinedConversion:
12416 case CK_LValueToRValue:
12418 case CK_ArrayToPointerDecay:
12420 case CK_FunctionToPointerDecay:
12422 case CK_IntegralCast:
12424 case CK_FloatingCast:
12426 case CK_IntegralToFloating:
12427 case CK_FloatingToIntegral:
12429 case CK_IntegralComplexCast:
12430 case CK_FloatingComplexCast:
12431 case CK_FloatingComplexToIntegralComplex:
12432 case CK_IntegralComplexToFloatingComplex:
12434 case CK_FloatingComplexToReal:
12435 case CK_FloatingRealToComplex:
12436 case CK_IntegralComplexToReal:
12437 case CK_IntegralRealToComplex:
12450 if (
const auto *ICE = dyn_cast<ImplicitCastExpr>(E))
12477 << 0 << FromType << ToType;
12482 llvm_unreachable(
"unhandled case in switch");
12509 if (NumEnumArgs == 1) {
12511 QualType OtherTy = LHSIsEnum ? RHSStrippedType : LHSStrippedType;
12517 if (NumEnumArgs == 2) {
12526 LHSStrippedType->
castAs<
EnumType>()->getDecl()->getIntegerType();
12537 LHSType = RHSType = IntType;
12549 std::optional<ComparisonCategoryType> CCT =
12561 assert(!
Type.isNull() &&
"composite type for <=> has not been set");
12602 if (
const auto *CL = dyn_cast<CharacterLiteral>(E.
get())) {
12603 if (CL->getValue() == 0)
12607 NullValue ?
"NULL" :
"(void *)0");
12608 }
else if (
const auto *CE = dyn_cast<CStyleCastExpr>(E.
get())) {
12615 NullValue ?
"NULL" :
"(void *)0");
12625 bool IsThreeWay = Opc == BO_Cmp;
12626 bool IsOrdered = IsRelational || IsThreeWay;
12637 if (!IsThreeWay || IsAnyPointerType(LHS) || IsAnyPointerType(RHS)) {
12684 auto computeResultTy = [&]() {
12693 std::optional<ComparisonCategoryType> CCT =
12698 if (CompositeTy->
isPointerType() && LHSIsNull != RHSIsNull) {
12702 Diag(Loc, diag::err_typecheck_three_way_comparison_of_pointer_and_zero)
12712 if (!IsOrdered && LHSIsNull != RHSIsNull) {
12713 bool IsEquality = Opc == BO_EQ;
12725 bool IsError = Opc == BO_Cmp;
12727 IsError ? diag::err_typecheck_ordered_comparison_of_function_pointers
12729 ? diag::warn_typecheck_ordered_comparison_of_function_pointers
12730 : diag::ext_typecheck_ordered_comparison_of_function_pointers;
12759 return computeResultTy();
12775 (IsOrdered ? 2 : 1) &&
12780 return computeResultTy();
12794 if (IsRelational) {
12799 Diag(Loc, diag::ext_typecheck_compare_complete_incomplete_pointers)
12805 }
else if (!IsRelational &&
12809 && !LHSIsNull && !RHSIsNull)
12816 if (LCanPointeeTy != RCanPointeeTy) {
12821 diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
12822 << LHSType << RHSType << 0
12828 CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion
12830 if (LHSIsNull && !RHSIsNull)
12835 return computeResultTy();
12846 if (!IsOrdered && LHSIsNull && RHSIsNull) {
12849 return computeResultTy();
12853 return computeResultTy();
12864 return computeResultTy();
12868 return computeResultTy();
12877 return computeResultTy();
12882 return computeResultTy();
12886 if (IsRelational &&
12895 if (isa<FunctionDecl>(DC))
12897 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
12898 if (CTSD->isInStdNamespace() &&
12899 llvm::StringSwitch<bool>(CTSD->getName())
12900 .Cases(
"less",
"less_equal",
"greater",
"greater_equal",
true)
12906 return computeResultTy();
12919 return computeResultTy();
12929 if (!LHSIsNull && !RHSIsNull &&
12931 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
12936 return computeResultTy();
12943 if (!LHSIsNull && !RHSIsNull) {
12948 Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
12952 if (LHSIsNull && !RHSIsNull)
12955 : CK_AnyPointerToBlockPointerCast);
12959 : CK_AnyPointerToBlockPointerCast);
12960 return computeResultTy();
12969 bool RPtrToVoid = RPT ? RPT->getPointeeType()->isVoidType() :
false;
12971 if (!LPtrToVoid && !RPtrToVoid &&
12979 if (LHSIsNull && !RHSIsNull) {
12985 RPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
12994 LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
12996 return computeResultTy();
13006 if (LHSIsNull && !RHSIsNull)
13010 return computeResultTy();
13016 CK_BlockPointerToObjCPointerCast);
13017 return computeResultTy();
13018 }
else if (!IsOrdered &&
13022 CK_BlockPointerToObjCPointerCast);
13023 return computeResultTy();
13028 unsigned DiagID = 0;
13029 bool isError =
false;
13038 isError ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero
13039 : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
13042 DiagID = diag::err_typecheck_comparison_of_pointer_integer;
13044 }
else if (IsOrdered)
13045 DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
13047 DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
13059 LHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13062 RHSIsNull ? CK_NullToPointer : CK_IntegralToPointer);
13063 return computeResultTy();
13067 if (!IsOrdered && RHSIsNull
13070 return computeResultTy();
13072 if (!IsOrdered && LHSIsNull
13075 return computeResultTy();
13078 if (
getLangOpts().getOpenCLCompatibleVersion() >= 200) {
13080 return computeResultTy();
13084 return computeResultTy();
13087 if (LHSIsNull && RHSType->
isQueueT()) {
13089 return computeResultTy();
13092 if (LHSType->
isQueueT() && RHSIsNull) {
13094 return computeResultTy();
13110 if (isa<ExtVectorType>(VTy)) {
13124 "Unhandled vector element size in vector compare");
13144 "Unhandled vector element size in vector compare");
13168 if (Opc == BO_Cmp) {
13169 Diag(Loc, diag::err_three_way_vector_comparison);
13200 Diag(Loc, diag::warn_deprecated_altivec_src_compat);
13230 if (Opc == BO_Cmp) {
13231 Diag(Loc, diag::err_three_way_vector_comparison);
13259 if (LHSBuiltinTy && RHSBuiltinTy && LHSBuiltinTy->
isSVEBool() &&
13260 RHSBuiltinTy->isSVEBool())
13279 bool Negative =
false;
13280 bool ExplicitPlus =
false;
13281 const auto *LHSInt = dyn_cast<IntegerLiteral>(XorLHS.
get());
13282 const auto *RHSInt = dyn_cast<IntegerLiteral>(XorRHS.
get());
13288 if (
const auto *UO = dyn_cast<UnaryOperator>(XorRHS.
get())) {
13290 if (Opc != UO_Minus && Opc != UO_Plus)
13292 RHSInt = dyn_cast<IntegerLiteral>(UO->getSubExpr());
13295 Negative = (Opc == UO_Minus);
13296 ExplicitPlus = !Negative;
13302 const llvm::APInt &LeftSideValue = LHSInt->getValue();
13304 if (LeftSideValue != 2 && LeftSideValue != 10)
13307 if (LeftSideValue.getBitWidth() != RightSideValue.getBitWidth())
13312 llvm::StringRef ExprStr =
13317 llvm::StringRef XorStr =
13320 if (XorStr ==
"xor")
13331 RightSideValue = -RightSideValue;
13332 RHSStr =
"-" + RHSStr;
13333 }
else if (ExplicitPlus) {
13334 RHSStr =
"+" + RHSStr;
13337 StringRef LHSStrRef = LHSStr;
13338 StringRef RHSStrRef = RHSStr;
13341 if (LHSStrRef.startswith(
"0b") || LHSStrRef.startswith(
"0B") ||
13342 RHSStrRef.startswith(
"0b") || RHSStrRef.startswith(
"0B") ||
13343 LHSStrRef.startswith(
"0x") || LHSStrRef.startswith(
"0X") ||
13344 RHSStrRef.startswith(
"0x") || RHSStrRef.startswith(
"0X") ||
13345 (LHSStrRef.size() > 1 && LHSStrRef.startswith(
"0")) ||
13346 (RHSStrRef.size() > 1 && RHSStrRef.startswith(
"0")) ||
13347 LHSStrRef.contains(
'\'') || RHSStrRef.contains(
'\''))
13352 const llvm::APInt XorValue = LeftSideValue ^ RightSideValue;
13353 int64_t RightSideIntValue = RightSideValue.getSExtValue();
13354 if (LeftSideValue == 2 && RightSideIntValue >= 0) {
13356 bool Overflow =
false;
13358 llvm::APInt PowValue = One.sshl_ov(RightSideValue, Overflow);
13360 if (RightSideIntValue < 64)
13361 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13362 << ExprStr <<
toString(XorValue, 10,
true) << (
"1LL << " + RHSStr)
13364 else if (RightSideIntValue == 64)
13365 S.
Diag(Loc, diag::warn_xor_used_as_pow)
13366 << ExprStr <<
toString(XorValue, 10,
true);
13370 S.
Diag(Loc, diag::warn_xor_used_as_pow_base_extra)
13371 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedExpr
13374 ExprRange, (RightSideIntValue == 0) ?
"1" : SuggestedExpr);
13377 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13378 << (
"0x2 ^ " + RHSStr) << SuggestXor;
13379 }
else if (LeftSideValue == 10) {
13380 std::string SuggestedValue =
"1e" + std::to_string(RightSideIntValue);
13381 S.
Diag(Loc, diag::warn_xor_used_as_pow_base)
13382 << ExprStr <<
toString(XorValue, 10,
true) << SuggestedValue
13384 S.
Diag(Loc, diag::note_xor_used_as_pow_silence)
13385 << (
"0xA ^ " + RHSStr) << SuggestXor;
13401 getLangOpts().getOpenCLCompatibleVersion() < 120 &&
13416 bool IsCompAssign) {
13417 if (!IsCompAssign) {
13433 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13442 if (LHSMatType && !RHSMatType) {
13450 if (!LHSMatType && RHSMatType) {
13462 bool IsCompAssign) {
13463 if (!IsCompAssign) {
13474 assert((LHSMatType || RHSMatType) &&
"At least one operand must be a matrix");
13476 if (LHSMatType && RHSMatType) {
13477 if (LHSMatType->getNumColumns() != RHSMatType->
getNumRows())
13485 QualType LHSELTy = LHSMatType->getElementType(),
13516 bool IsCompAssign =
13517 Opc == BO_AndAssign || Opc == BO_OrAssign || Opc == BO_XorAssign;
13528 LegalBoolVecOperator,
13558 ExprResult LHSResult = LHS, RHSResult = RHS;
13561 if (LHSResult.
isInvalid() || RHSResult.isInvalid())
13563 LHS = LHSResult.
get();
13564 RHS = RHSResult.
get();
13583 bool EnumConstantInBoolContext =
false;
13585 if (
const auto *DREHS = dyn_cast<DeclRefExpr>(HS.get())) {
13586 const auto *ECDHS = dyn_cast<EnumConstantDecl>(DREHS->getDecl());
13587 if (ECDHS && ECDHS->getInitVal() != 0 && ECDHS->getInitVal() != 1)
13588 EnumConstantInBoolContext =
true;
13592 if (EnumConstantInBoolContext)
13593 Diag(Loc, diag::warn_enum_constant_in_bool_context);
13612 (Result != 0 && Result != 1)) {
13613 Diag(Loc, diag::warn_logical_instead_of_bitwise)
13616 Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
13617 << (Opc == BO_LAnd ?
"&" :
"|")
13620 Opc == BO_LAnd ?
"&" :
"|");
13621 if (Opc == BO_LAnd)
13623 Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13679 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
13680 if (!ME)
return false;
13684 if (!
Base)
return false;
13685 return Base->getMethodDecl() !=
nullptr;
13704 if (
var->getType().isConstQualified())
return NCCK_None;
13705 assert(
var->hasLocalStorage() &&
"capture added 'const' to non-local?");
13713 if (
auto *FD = dyn_cast<FunctionDecl>(DC))
13714 if (
var->isInitCapture() &&
13715 FD->getTemplateInstantiationPattern() ==
var->getDeclContext())
13717 if (DC ==
var->getDeclContext())
13723 if (!
var->isInitCapture())
13756 bool DiagnosticEmitted =
false;
13760 bool IsDereference =
false;
13761 bool NextIsDereference =
false;
13765 IsDereference = NextIsDereference;
13768 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
13769 NextIsDereference = ME->isArrow();
13770 const ValueDecl *VD = ME->getMemberDecl();
13771 if (
const FieldDecl *Field = dyn_cast<FieldDecl>(VD)) {
13773 if (Field->isMutable()) {
13774 assert(DiagnosticEmitted &&
"Expected diagnostic not emitted.");
13779 if (!DiagnosticEmitted) {
13780 S.
Diag(Loc, diag::err_typecheck_assign_const)
13782 << Field->getType();
13783 DiagnosticEmitted =
true;
13786 <<
ConstMember <<
false << Field << Field->getType()
13787 << Field->getSourceRange();
13791 }
else if (
const VarDecl *VDecl = dyn_cast<VarDecl>(VD)) {
13792 if (VDecl->getType().isConstQualified()) {
13793 if (!DiagnosticEmitted) {
13794 S.
Diag(Loc, diag::err_typecheck_assign_const)
13796 << VDecl->getType();
13797 DiagnosticEmitted =
true;
13800 <<
ConstMember <<
true << VDecl << VDecl->getType()
13801 << VDecl->getSourceRange();
13808 dyn_cast<ArraySubscriptExpr>(E)) {
13812 dyn_cast<ExtVectorElementExpr>(E)) {
13819 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
13823 if (!DiagnosticEmitted) {
13824 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
13826 DiagnosticEmitted =
true;
13829 diag::note_typecheck_assign_const)
13833 }
else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
13835 if (
const ValueDecl *VD = DRE->getDecl()) {
13837 if (!DiagnosticEmitted) {
13838 S.
Diag(Loc, diag::err_typecheck_assign_const)
13840 DiagnosticEmitted =
true;
13842 S.
Diag(VD->getLocation(), diag::note_typecheck_assign_const)
13843 <<
ConstVariable << VD << VD->getType() << VD->getSourceRange();
13846 }
else if (isa<CXXThisExpr>(E)) {
13848 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) {
13849 if (MD->isConst()) {
13850 if (!DiagnosticEmitted) {
13851 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
13853 DiagnosticEmitted =
true;
13855 S.
Diag(MD->getLocation(), diag::note_typecheck_assign_const)
13862 if (DiagnosticEmitted)
13866 S.
Diag(Loc, diag::err_typecheck_assign_const) << ExprRange <<
ConstUnknown;
13879 bool &DiagnosticEmitted) {
13880 std::vector<const RecordType *> RecordTypeList;
13881 RecordTypeList.push_back(Ty);
13882 unsigned NextToCheckIndex = 0;
13885 while (RecordTypeList.size() > NextToCheckIndex) {
13886 bool IsNested = NextToCheckIndex > 0;
13888 RecordTypeList[NextToCheckIndex]->getDecl()->fields()) {
13890 QualType FieldTy = Field->getType();
13892 if (!DiagnosticEmitted) {
13893 S.
Diag(Loc, diag::err_typecheck_assign_const)
13895 << IsNested << Field;
13896 DiagnosticEmitted =
true;
13898 S.
Diag(Field->getLocation(), diag::note_typecheck_assign_const)
13900 << FieldTy << Field->getSourceRange();
13906 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
13907 RecordTypeList.push_back(FieldRecTy);
13910 ++NextToCheckIndex;
13919 assert(Ty->
isRecordType() &&
"lvalue was not record?");
13922 bool DiagEmitted =
false;
13924 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(E))
13927 else if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
13952 unsigned DiagID = 0;
13953 bool NeedType =
false;
13960 DiagID = diag::err_block_decl_ref_not_modifiable_lvalue;
13962 DiagID = diag::err_lambda_decl_ref_not_modifiable_lvalue;
13970 if (declRef && isa<VarDecl>(declRef->
getDecl())) {
13975 if (
var->isARCPseudoStrong() &&
13976 (!
var->getTypeSourceInfo() ||
13977 !
var->getTypeSourceInfo()->getType().isConstQualified())) {
13983 ? diag::err_typecheck_arc_assign_self_class_method
13984 : diag::err_typecheck_arc_assign_self;
13987 }
else if (
var->hasAttr<ObjCExternallyRetainedAttr>() ||
13988 isa<ParmVarDecl>(
var)) {
13989 DiagID = diag::err_typecheck_arc_assign_externally_retained;
13993 DiagID = diag::err_typecheck_arr_assign_enumeration;
13997 if (Loc != OrigLoc)
14023 DiagID = diag::err_typecheck_array_not_modifiable_lvalue;
14027 DiagID = diag::err_typecheck_non_object_not_modifiable_lvalue;
14031 DiagID = diag::err_typecheck_lvalue_casts_not_supported;
14034 llvm_unreachable(
"did not take early return for MLV_Valid");
14038 DiagID = diag::err_typecheck_expression_not_modifiable_lvalue;
14043 diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E);
14045 DiagID = diag::err_typecheck_duplicate_vector_components_not_mlvalue;
14048 llvm_unreachable(
"readonly properties should be processed differently");
14050 DiagID = diag::err_readonly_message_assignment;
14053 DiagID = diag::err_no_subobject_property_setting;
14058 if (Loc != OrigLoc)
14080 MemberExpr *ML = dyn_cast<MemberExpr>(LHSExpr);
14081 MemberExpr *MR = dyn_cast<MemberExpr>(RHSExpr);
14083 if (!(isa<CXXThisExpr>(ML->
getBase()) && isa<CXXThisExpr>(MR->
getBase())))
14089 if (LHSDecl != RHSDecl)
14094 if (RefTy->getPointeeType().isVolatileQualified())
14097 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 0;
14107 Sema.
Diag(Loc, diag::warn_identity_field_assign) << 1;
14131 Diag(Loc, diag::err_opencl_half_load_store) << 1
14137 if (CompoundType.
isNull()) {
14156 Diag(Loc, diag::err_objc_object_assignment)
14163 RHSCheck = ICE->getSubExpr();
14164 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(RHSCheck)) {
14165 if ((UO->getOpcode() == UO_Plus || UO->getOpcode() == UO_Minus) &&
14166 Loc.
isFileID() && UO->getOperatorLoc().isFileID() &&
14172 UO->getSubExpr()->getBeginLoc().
isFileID()) {
14173 Diag(Loc, diag::warn_not_compound_assign)
14174 << (UO->getOpcode() == UO_Plus ?
"+" :
"-")
14175 <<
SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc());
14185 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InnerLHS);
14221 if (CompoundType.
isNull()) {
14247 if (
const CastExpr *CE = dyn_cast<CastExpr>(E)) {
14248 if (CE->getCastKind() == CK_ToVoid) {
14254 CE->getSubExpr()->getType()->isDependentType()) {
14259 if (
const auto *CE = dyn_cast<CallExpr>(E))
14260 return CE->getCallReturnType(Context)->isVoidType();
14283 const unsigned ForIncrementFlags =
14289 if ((ScopeFlags & ForIncrementFlags) == ForIncrementFlags ||
14290 (ScopeFlags & ForInitFlags) == ForInitFlags)
14295 while (
const BinaryOperator *BO = dyn_cast<BinaryOperator>(LHS)) {
14296 if (BO->getOpcode() != BO_Comma)
14298 LHS = BO->getRHS();
14305 Diag(Loc, diag::warn_comma_operator);
14309 LangOpts.CPlusPlus ?
"static_cast<void>("
14341 diag::err_incomplete_type);
14356 bool IsInc,
bool IsPrefix) {
14365 ResType = ResAtomicType->getValueType();
14367 assert(!ResType.
isNull() &&
"no type for increment/decrement expression");
14377 : diag::warn_increment_bool)
14381 S.
Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType;
14397 S.
Diag(OpLoc, diag::ext_integer_increment_complex)
14414 S.
Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
14425 S.
Diag(OpLoc, diag::warn_deprecated_increment_decrement_volatile)
14426 << IsInc << ResType;
14459 case Stmt::DeclRefExprClass:
14460 return cast<DeclRefExpr>(E)->getDecl();
14461 case Stmt::MemberExprClass:
14465 if (cast<MemberExpr>(E)->isArrow())
14469 case Stmt::ArraySubscriptExprClass: {
14472 Expr*
Base = cast<ArraySubscriptExpr>(E)->getBase();
14474 if (ICE->getSubExpr()->getType()->isArrayType())
14479 case Stmt::UnaryOperatorClass: {
14491 case Stmt::ParenExprClass:
14493 case Stmt::ImplicitCastExprClass:
14497 case Stmt::CXXUuidofExprClass:
14498 return cast<CXXUuidofExpr>(E)->getGuidDecl();
14507 AO_Vector_Element = 1,
14508 AO_Property_Expansion = 2,
14509 AO_Register_Variable = 3,
14510 AO_Matrix_Element = 4,
14531 if (PTy->getKind() == BuiltinType::Overload) {
14533 if (!isa<OverloadExpr>(E)) {
14534 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
14535 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof_addrof_function)
14541 if (isa<UnresolvedMemberExpr>(Ovl))
14543 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14551 if (PTy->getKind() == BuiltinType::UnknownAny)
14554 if (PTy->getKind() == BuiltinType::BoundMember) {
14555 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14578 auto* VarRef = dyn_cast<DeclRefExpr>(op);
14579 if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) {
14580 Diag(op->
getExprLoc(), diag::err_opencl_taking_address_capture);
14588 if (uOp->getOpcode() == UO_Deref)
14591 return uOp->getSubExpr()->getType();
14598 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(dcl))
14604 unsigned AddressOfError = AO_No_Error;
14609 : diag::ext_typecheck_addrof_temporary)
14616 }
else if (isa<ObjCSelectorExpr>(op)) {
14623 if (!isa<DeclRefExpr>(op)) {
14624 Diag(OpLoc, diag::err_invalid_form_pointer_member_function)
14632 if (OrigOp.
get() != DRE) {
14633 Diag(OpLoc, diag::err_parens_pointer_member_function)
14639 Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14644 Diag(OpLoc, diag::err_unqualified_pointer_member_function)
14651 if (isa<CXXDestructorDecl>(MD))
14665 if (isa<PseudoObjectExpr>(op)) {
14666 AddressOfError = AO_Property_Expansion;
14668 Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof)
14675 AddressOfError = AO_Bit_Field;
14678 AddressOfError = AO_Vector_Element;
14681 AddressOfError = AO_Matrix_Element;
14685 if (
const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
14690 AddressOfError = AO_Register_Variable;
14692 }
else if (isa<MSPropertyDecl>(dcl)) {
14693 AddressOfError = AO_Property_Expansion;
14694 }
else if (isa<FunctionTemplateDecl>(dcl)) {
14696 }
else if (isa<FieldDecl>(dcl) || isa<IndirectFieldDecl>(dcl)) {
14700 if (isa<DeclRefExpr>(op) && cast<DeclRefExpr>(op)->getQualifier()) {
14705 diag::err_cannot_form_pointer_to_member_of_reference_type)
14710 while (cast<RecordDecl>(Ctx)->isAnonymousStructOrUnion())
14724 llvm_unreachable(
"Unknown/unexpected decl type");
14727 if (AddressOfError != AO_No_Error) {
14743 CheckAddressOfPackedMember(op);
14749 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Exp);
14755 const ParmVarDecl *Param = dyn_cast<ParmVarDecl>(D);
14759 if (!FD->hasAttr<NonNullAttr>() && !Param->
hasAttr<NonNullAttr>())
14762 FD->ModifiedNonNullParams.insert(Param);
14768 bool IsAfterAmp =
false) {
14775 Op = ConvResult.
get();
14779 if (isa<CXXReinterpretCastExpr>(Op)) {
14787 Result = PT->getPointeeType();
14791 Result = OPT->getPointeeType();
14795 if (PR.
get() != Op)
14799 if (Result.isNull()) {
14800 S.
Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer)
14805 if (Result->isVoidType()) {
14811 S.
Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer_cpp)
14814 S.
Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer)
14822 if (!S.
getLangOpts().CPlusPlus && Result.isCForbiddenLValueType())
14831 default: llvm_unreachable(
"Unknown binop!");
14832 case tok::periodstar: Opc = BO_PtrMemD;
break;
14833 case tok::arrowstar: Opc = BO_PtrMemI;
break;
14834 case tok::star: Opc = BO_Mul;
break;
14835 case tok::slash: Opc = BO_Div;
break;
14836 case tok::percent: Opc = BO_Rem;
break;
14837 case tok::plus: Opc = BO_Add;
break;
14838 case tok::minus: Opc = BO_Sub;
break;
14839 case tok::lessless: Opc = BO_Shl;
break;
14840 case tok::greatergreater: Opc = BO_Shr;
break;
14841 case tok::lessequal: Opc = BO_LE;
break;
14842 case tok::less: Opc = BO_LT;
break;
14843 case tok::greaterequal: Opc = BO_GE;
break;
14844 case tok::greater: Opc = BO_GT;
break;
14845 case tok::exclaimequal: Opc = BO_NE;
break;
14846 case tok::equalequal: Opc = BO_EQ;
break;
14847 case tok::spaceship: Opc = BO_Cmp;
break;
14848 case tok::amp: Opc = BO_And;
break;
14849 case tok::caret: Opc = BO_Xor;
break;
14850 case tok::pipe: Opc = BO_Or;
break;
14851 case tok::ampamp: Opc = BO_LAnd;
break;
14852 case tok::pipepipe: Opc = BO_LOr;
break;
14853 case tok::equal: Opc = BO_Assign;
break;
14854 case tok::starequal: Opc = BO_MulAssign;
break;
14855 case tok::slashequal: Opc = BO_DivAssign;
break;
14856 case tok::percentequal: Opc = BO_RemAssign;
break;
14857 case tok::plusequal: Opc = BO_AddAssign;
break;
14858 case tok::minusequal: Opc = BO_SubAssign;
break;
14859 case tok::lesslessequal: Opc = BO_ShlAssign;
break;
14860 case tok::greatergreaterequal: Opc = BO_ShrAssign;
break;
14861 case tok::ampequal: Opc = BO_AndAssign;
break;
14862 case tok::caretequal: Opc = BO_XorAssign;
break;
14863 case tok::pipeequal: Opc = BO_OrAssign;
break;
14864 case tok::comma: Opc = BO_Comma;
break;
14873 default: llvm_unreachable(
"Unknown unary op!");
14874 case tok::plusplus: Opc = UO_PreInc;
break;
14875 case tok::minusminus: Opc = UO_PreDec;
break;
14876 case tok::amp: Opc = UO_AddrOf;
break;
14877 case tok::star: Opc = UO_Deref;
break;
14878 case tok::plus: Opc = UO_Plus;
break;
14879 case tok::minus: Opc = UO_Minus;
break;
14880 case tok::tilde: Opc = UO_Not;
break;
14881 case tok::exclaim: Opc = UO_LNot;
break;
14882 case tok::kw___real: Opc = UO_Real;
break;
14883 case tok::kw___imag: Opc = UO_Imag;
break;
14884 case tok::kw___extension__: Opc = UO_Extension;
break;
14900 if (!isa<ParmVarDecl>(SelfAssigned))
14902 const auto *Method =
14916 llvm::find_if(
Parent->fields(),
14918 return F->getDeclName() == Name;
14920 return (Field !=
Parent->field_end()) ? *Field :
nullptr;
14935 const DeclRefExpr *LHSDeclRef = dyn_cast<DeclRefExpr>(LHSExpr);
14936 const DeclRefExpr *RHSDeclRef = dyn_cast<DeclRefExpr>(RHSExpr);
14937 if (!LHSDeclRef || !RHSDeclRef ||
14945 if (LHSDecl != RHSDecl)
14950 if (RefTy->getPointeeType().isVolatileQualified())
14953 auto Diag = S.
Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin
14954 : diag::warn_self_assignment_overloaded)
14959 Diag << 1 << SelfAssignField
14972 const Expr *ObjCPointerExpr =
nullptr, *OtherExpr =
nullptr;
14977 ObjCPointerExpr = LHS;
14981 ObjCPointerExpr = RHS;
14989 if (ObjCPointerExpr && isa<IntegerLiteral>(OtherExpr->IgnoreParenCasts())) {
14990 unsigned Diag = diag::warn_objc_pointer_masking;
14998 StringRef SelArg0 = S.getNameForSlot(0);
14999 if (SelArg0.startswith(
"performSelector"))
15000 Diag = diag::warn_objc_pointer_masking_performSelector;
15011 if (
auto *DRE = dyn_cast<DeclRefExpr>(E))
15012 return DRE->getDecl();
15013 if (
auto *ME = dyn_cast<MemberExpr>(E))
15014 return ME->getMemberDecl();
15015 if (
auto *IRE = dyn_cast<ObjCIvarRefExpr>(E))
15016 return IRE->getDecl();
15031 "Result must be a vector of half or short");
15034 "both operands expected to be a half vector");
15046 ResultTy, VK, OK, OpLoc, FPFeatures,
15047 BinOpResTy, BinOpResTy);
15051 BinOpResTy, VK, OK, OpLoc, FPFeatures);
15055 static std::pair<ExprResult, ExprResult>
15065 RHS,
nullptr,
false,
15066 [Opc, LHS](
Expr *E) {
15067 if (Opc != BO_Assign)
15074 return std::make_pair(LHS, RHS);
15081 if (!OpRequiresConversion || Ctx.
getLangOpts().NativeHalfType ||
15085 auto HasVectorOfHalfType = [&Ctx](
Expr *E) {
15095 return VT->getElementType().getCanonicalType() == Ctx.
HalfTy;
15100 return HasVectorOfHalfType(E0) && (!E1 || HasVectorOfHalfType(E1));
15122 if (Init.isInvalid())
15124 RHSExpr = Init.get();
15134 bool ConvertHalfVec =
false;
15137 if (!LHS.
isUsable() || !RHS.isUsable())
15147 if (BO_Assign == Opc)
15148 Diag(OpLoc, diag::err_opencl_atomic_init) << 0 << SR;
15176 if (!ResultTy.
isNull()) {
15193 if (
auto *BE = dyn_cast<BlockExpr>(RHS.get()->IgnoreParens()))
15195 if (
auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
15196 if (VD->hasLocalStorage() &&
getCurScope()->isDeclScope(VD))
15197 BE->getBlockDecl()->setCanAvoidCopyToHeap();
15208 Opc == BO_PtrMemI);
15212 ConvertHalfVec =
true;
15220 ConvertHalfVec =
true;
15224 ConvertHalfVec =
true;
15235 ConvertHalfVec =
true;
15240 ConvertHalfVec =
true;
15244 ConvertHalfVec =
true;
15257 ConvertHalfVec =
true;
15262 ConvertHalfVec =
true;
15264 Opc == BO_DivAssign);
15265 CompLHSTy = CompResultTy;
15272 CompLHSTy = CompResultTy;
15278 ConvertHalfVec =
true;
15285 ConvertHalfVec =
true;
15294 CompLHSTy = CompResultTy;
15305 CompLHSTy = CompResultTy;
15313 VK = RHS.get()->getValueKind();
15314 OK = RHS.get()->getObjectKind();
15328 "both sides are half vectors or neither sides are");
15333 CheckArrayAccess(LHS.
get());
15334 CheckArrayAccess(RHS.get());
15340 if (ObjectSetClass && isa<ObjCIsaExpr>(LHS.
get())) {
15344 "object_setClass(")
15357 if (CompResultTy.
isNull()) {
15358 if (ConvertHalfVec)
15378 if (ConvertHalfVec)
15383 Context, LHS.
get(), RHS.get(), Opc, ResultTy, VK, OK, OpLoc,
15400 if (isLeftComp == isRightComp)
15405 bool isLeftBitwise = LHSBO && LHSBO->
isBitwiseOp();
15406 bool isRightBitwise = RHSBO && RHSBO->
isBitwiseOp();
15407 if (isLeftBitwise || isRightBitwise)
15419 Self.
Diag(OpLoc, diag::warn_precedence_bitwise_rel)
15422 Self.
PDiag(diag::note_precedence_silence) << OpStr,
15423 (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange());
15425 Self.
PDiag(diag::note_precedence_bitwise_first)
15440 Self.
PDiag(diag::note_precedence_silence)
15449 if (Bop->getOpcode() == BO_LAnd) {
15452 if (!isa<StringLiteral>(Bop->getLHS()->IgnoreParenImpCasts()))
15454 }
else if (Bop->getOpcode() == BO_LOr) {
15455 if (
BinaryOperator *RBop = dyn_cast<BinaryOperator>(Bop->getRHS())) {
15458 if (RBop->getOpcode() == BO_LAnd &&
15459 isa<StringLiteral>(RBop->getRHS()->IgnoreParenImpCasts()))
15470 if (Bop->getOpcode() == BO_LAnd) {
15473 if (!isa<StringLiteral>(Bop->getRHS()->IgnoreParenImpCasts()))
15485 if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) {
15486 S.
Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op)
15488 << Bop->getSourceRange() << OpLoc;
15490 S.
PDiag(diag::note_precedence_silence)
15491 << Bop->getOpcodeStr(),
15492 Bop->getSourceRange());
15500 if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) {
15501 StringRef Op = Bop->getOpcodeStr();
15502 S.
Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift)
15503 << Bop->getSourceRange() << OpLoc <<
Shift << Op;
15505 S.
PDiag(diag::note_precedence_silence) << Op,
15506 Bop->getSourceRange());
15522 if (
Kind != OO_LessLess &&
Kind != OO_GreaterGreater)
15525 S.
Diag(OpLoc, diag::warn_overloaded_shift_in_comparison)
15527 << (
Kind == OO_LessLess);
15529 S.
PDiag(diag::note_precedence_silence)
15530 << (
Kind == OO_LessLess ?
"<<" :
">>"),
15533 S, OpLoc, S.
PDiag(diag::note_evaluate_comparison_first),
15547 if ((Opc == BO_Or || Opc == BO_Xor) &&
15555 if (Opc == BO_LOr && !OpLoc.
isMacroID()) {
15561 || Opc == BO_Shr) {
15578 assert(LHSExpr &&
"ActOnBinOp(): missing left expression");
15579 assert(RHSExpr &&
"ActOnBinOp(): missing right expression");
15584 return BuildBinOp(S, TokLoc, Opc, LHSExpr, RHSExpr);
15590 if (OverOp !=
OO_None && OverOp != OO_Equal)
15635 LHSExpr = LHS.
get();
15636 RHSExpr = RHS.
get();
15647 if (pty->getKind() == BuiltinType::PseudoObject &&
15660 RHSExpr = resolvedRHS.
get();
15674 (pty->getKind() == BuiltinType::BoundMember ||
15675 pty->getKind() == BuiltinType::Overload)) {
15676 auto *OE = dyn_cast<OverloadExpr>(LHSExpr);
15677 if (OE && !OE->hasTemplateKeyword() && !OE->hasExplicitTemplateArgs() &&
15678 llvm::any_of(OE->decls(), [](
NamedDecl *ND) {
15679 return isa<FunctionTemplateDecl>(ND);
15681 Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc()
15682 : OE->getNameLoc(),
15683 diag::err_template_kw_missing)
15684 << OE->getName().getAsString() <<
"";
15691 LHSExpr = LHS.
get();
15698 if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) {
15714 RHSExpr = resolvedRHS.
get();
15734 "Should only occur in error-recovery path.");
15740 Context, LHSExpr, RHSExpr, Opc,
15760 ResultType = RHSExpr->
getType();
15792 bool CanOverflow =
false;
15794 bool ConvertHalfVec =
false;
15803 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15810 if (Opc == UO_AddrOf)
15811 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
15812 if (Opc == UO_Deref)
15813 return ExprError(
Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
15823 Opc == UO_PreInc ||
15825 Opc == UO_PreInc ||
15831 CheckAddressOfNoDeref(InputExpr);
15843 CanOverflow = Opc == UO_Minus &&
15854 if (ConvertHalfVec)
15874 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15887 Diag(OpLoc, diag::ext_integer_complement_complex)
15896 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15899 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15930 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15940 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15949 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15956 return ExprError(
Diag(OpLoc, diag::err_typecheck_unary_expr)
15988 "the co_await expression must be non-dependant before "
15989 "building operator co_await");
15999 if (Opc != UO_AddrOf && Opc != UO_Deref)
16000 CheckArrayAccess(Input.
get());
16006 if (Opc == UO_Deref && UO->getType()->hasAttr(attr::NoDeref) &&
16007 !isa<ArrayType>(UO->getType().getDesugaredType(
Context)) &&
16012 if (ConvertHalfVec)
16021 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
16022 if (!DRE->getQualifier())
16029 if (isa<FieldDecl>(VD) || isa<IndirectFieldDecl>(VD))
16032 return Method->isInstance();
16038 if (!ULE->getQualifier())
16043 if (Method->isInstance())
16064 if (pty->getKind() == BuiltinType::PseudoObject &&
16069 if (Opc == UO_Extension)
16074 if (Opc == UO_AddrOf &&
16075 (pty->getKind() == BuiltinType::Overload ||
16076 pty->getKind() == BuiltinType::UnknownAny ||
16077 pty->getKind() == BuiltinType::BoundMember))
16082 if (Result.isInvalid())
return ExprError();
16083 Input = Result.get();
16103 Expr *Input,
bool IsAfterAmp) {
16141 assert(SubStmt && isa<CompoundStmt>(SubStmt) &&
"Invalid action invocation!");
16147 "cleanups within StmtExpr not correctly bound!");
16157 bool StmtExprMayBindToTemp =
false;
16160 if (
const auto *LastStmt =
16163 StmtExprMayBindToTemp =
true;
16164 Ty =
Value->getType();
16171 Expr *ResStmtExpr =
16173 if (StmtExprMayBindToTemp)
16175 return ResStmtExpr;
16198 auto *
Cast = dyn_cast<ImplicitCastExpr>(E);
16199 if (
Cast &&
Cast->getCastKind() == CK_ARCConsumeObject)
16200 return Cast->getSubExpr();
16221 return ExprError(
Diag(BuiltinLoc, diag::err_offsetof_record_type)
16222 << ArgTy << TypeRange);
16228 diag::err_offsetof_incomplete_type, TypeRange))
16231 bool DidWarnAboutNonPOD =
false;
16236 if (OC.isBrackets) {
16241 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_array_type)
16261 Comps.push_back(
OffsetOfNode(OC.LocStart, Exprs.size(), OC.LocEnd));
16262 Exprs.push_back(Idx);
16270 Comps.push_back(
OffsetOfNode(OC.LocStart, OC.U.IdentInfo, OC.LocEnd));
16277 diag::err_offsetof_incomplete_type))
16283 return ExprError(
Diag(OC.LocEnd, diag::err_offsetof_record_type)
16295 bool IsSafe =
LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD();
16297 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
16298 : diag::ext_offsetof_non_pod_type;
16300 if (!IsSafe && !DidWarnAboutNonPOD &&
16303 <<
SourceRange(Components[0].LocStart, OC.LocEnd)
16305 DidWarnAboutNonPOD =
true;
16315 MemberDecl = IndirectMemberDecl->getAnonField();
16320 << OC.U.IdentInfo << RD <<
SourceRange(OC.LocStart,
16328 Diag(OC.LocEnd, diag::err_offsetof_bitfield)
16336 if (IndirectMemberDecl)
16337 Parent = cast<RecordDecl>(IndirectMemberDecl->getDeclContext());
16344 if (Paths.getDetectedVirtual()) {
16345 Diag(OC.LocEnd, diag::err_offsetof_field_of_virtual_base)
16356 if (IndirectMemberDecl) {
16357 for (
auto *FI : IndirectMemberDecl->chain()) {
16358 assert(isa<FieldDecl>(FI));
16360 cast<FieldDecl>(FI), OC.LocEnd));
16363 Comps.push_back(
OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd));
16369 Comps, Exprs, RParenLoc);
16395 assert((CondExpr && LHSExpr && RHSExpr) &&
"Missing type argument(s)");
16400 bool CondIsTrue =
false;
16407 CondExpr, &condEval, diag::err_typecheck_choose_expr_requires_constant);
16410 CondExpr = CondICE.
get();
16411 CondIsTrue = condEval.getZExtValue();
16414 Expr *ActiveExpr = CondIsTrue ? LHSExpr : RHSExpr;
16416 resType = ActiveExpr->
getType();
16422 resType, VK, OK, RPLoc, CondIsTrue);
16435 Decl *ManglingContextDecl;
16436 std::tie(MCtx, ManglingContextDecl) =
16440 Block->setBlockMangling(ManglingNumber, ManglingContextDecl);
16462 "block-id should have no identifier!");
16484 "GetTypeForDeclarator made a non-function block signature");
16500 unsigned Size = Result.getFullDataSize();
16512 QualType RetTy = Fn->getReturnType();
16514 (isa<FunctionProtoType>(Fn) && cast<FunctionProtoType>(Fn)->isVariadic());
16530 if (ExplicitSignature) {
16531 for (
unsigned I = 0, E = ExplicitSignature.
getNumParams(); I != E; ++I) {
16539 Params.push_back(Param);
16545 for (
const auto &I : Fn->param_types()) {
16548 Params.push_back(Param);
16553 if (!Params.empty()) {
16564 AI->setOwningFunction(CurBlock->
TheDecl);
16567 if (AI->getIdentifier()) {
16593 Diag(CaretLoc, diag::err_blocks_disable) <<
LangOpts.OpenCL;
16599 "cleanups within block not correctly bound!");
16612 bool NoReturn = BD->
hasAttr<NoReturnAttr>();
16620 if (NoReturn && !Ext.getNoReturn()) Ext = Ext.
withNoReturn(
true);
16623 if (isa<FunctionNoProtoType>(FTy)) {
16658 BD->
setBody(cast<CompoundStmt>(Body));
16660 if (Body &&
getCurFunction()->HasPotentialAvailabilityViolations)
16685 Expr *CopyExpr =
nullptr;
16694 if (isa<ParmVarDecl>(Var))
16713 if (!Result.isInvalid() &&
16714 !Result.get()->getType().isConstQualified()) {
16716 Result.get()->getType().withConst(),
16720 if (!Result.isInvalid()) {
16724 Loc, Result.get());
16730 if (!Result.isInvalid() &&
16731 !cast<CXXConstructExpr>(Result.get())->getConstructor()
16734 CopyExpr = Result.get();
16741 Captures.push_back(NewCap);
16753 if (Result->getBlockDecl()->hasCaptures()) {
16760 for (
const auto &CI : Result->getBlockDecl()->captures()) {
16785 Expr *OrigExpr = E;
16825 if (Result.isInvalid())
16834 if (Init.isInvalid())
16836 E = Init.getAs<
Expr>();
16850 diag::err_first_argument_to_va_arg_not_of_type_va_list)
16855 diag::err_second_parameter_to_va_arg_incomplete,
16861 diag::err_second_parameter_to_va_arg_abstract,
16868 ? diag::warn_second_parameter_to_va_arg_ownership_qualified
16869 : diag::warn_second_parameter_to_va_arg_not_pod)
16899 UnderlyingType = ET->getDecl()->getIntegerType();
16922 if (!PromoteType.
isNull())
16924 PDiag(diag::warn_second_parameter_to_va_arg_never_compatible)
16946 llvm_unreachable(
"I don't know size of pointer!");
16963 if ((SLDecl->isCompleteDefinition() || SLDecl->isBeingDefined()) &&
16972 S.
Diag(Loc, diag::err_std_source_location_impl_not_found);
16980 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
16984 unsigned Count = 0;
16986 StringRef Name = F->getName();
16988 if (Name ==
"_M_file_name") {
16989 if (F->getType() !=
16993 }
else if (Name ==
"_M_function_name") {
16994 if (F->getType() !=
16998 }
else if (Name ==
"_M_line") {
16999 if (!F->getType()->isIntegerType())
17002 }
else if (Name ==
"_M_column") {
17003 if (!F->getType()->isIntegerType())
17012 S.
Diag(Loc, diag::err_std_source_location_impl_malformed);
17074 if (OV->getSourceExpr())
17077 if (
auto *SL = dyn_cast<StringLiteral>(SrcExpr)) {
17079 !(
ID &&
ID->getIdentifier()->isStr(
"NSString")))
17081 if (!SL->isOrdinary())
17085 Diag(SL->getBeginLoc(), diag::err_missing_atsign_prefix)
17092 if ((isa<IntegerLiteral>(SrcExpr) || isa<CharacterLiteral>(SrcExpr) ||
17093 isa<FloatingLiteral>(SrcExpr) || isa<ObjCBoolLiteralExpr>(SrcExpr) ||
17094 isa<CXXBoolLiteralExpr>(SrcExpr)) &&
17097 if (!
ID || !
ID->getIdentifier()->isStr(
"NSNumber"))
17115 const Expr *SrcExpr) {
17124 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
17137 bool *Complained) {
17139 *Complained =
false;
17142 bool CheckInferredResultType =
false;
17144 unsigned DiagKind = 0;
17146 bool MayHaveConvFixit =
false;
17147 bool MayHaveFunctionDiff =
false;
17158 DiagKind = diag::err_typecheck_convert_pointer_int;
17161 DiagKind = diag::ext_typecheck_convert_pointer_int;
17164 MayHaveConvFixit =
true;
17168 DiagKind = diag::err_typecheck_convert_int_pointer;
17171 DiagKind = diag::ext_typecheck_convert_int_pointer;
17174 MayHaveConvFixit =
true;
17178 diag::warn_typecheck_convert_incompatible_function_pointer_strict;
17180 MayHaveConvFixit =
true;
17184 DiagKind = diag::err_typecheck_convert_incompatible_function_pointer;
17187 DiagKind = diag::ext_typecheck_convert_incompatible_function_pointer;
17190 MayHaveConvFixit =
true;
17194 DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
17196 DiagKind = diag::err_typecheck_convert_incompatible_pointer;
17199 DiagKind = diag::ext_typecheck_convert_incompatible_pointer;
17203 if (!CheckInferredResultType) {
17205 }
else if (CheckInferredResultType) {
17209 MayHaveConvFixit =
true;
17213 DiagKind = diag::err_typecheck_convert_incompatible_pointer_sign;
17216 DiagKind = diag::ext_typecheck_convert_incompatible_pointer_sign;
17221 DiagKind = diag::err_typecheck_convert_pointer_void_func;
17224 DiagKind = diag::ext_typecheck_convert_pointer_void_func;
17236 DiagKind = diag::err_typecheck_incompatible_address_space;
17240 DiagKind = diag::err_typecheck_incompatible_ownership;
17244 llvm_unreachable(
"unknown error case for discarding qualifiers!");
17261 DiagKind = diag::err_typecheck_convert_discards_qualifiers;
17264 DiagKind = diag::ext_typecheck_convert_discards_qualifiers;
17271 DiagKind = diag::err_nested_pointer_qualifier_mismatch;
17273 DiagKind = diag::ext_nested_pointer_qualifier_mismatch;
17277 DiagKind = diag::err_typecheck_incompatible_nested_address_space;
17281 DiagKind = diag::err_int_to_block_pointer;
17285 DiagKind = diag::err_typecheck_convert_incompatible_block_pointer;
17292 for (
auto *srcProto : srcOPT->
quals()) {
17298 IFace = IFaceT->getDecl();
17303 for (
auto *dstProto : dstOPT->
quals()) {
17309 IFace = IFaceT->getDecl();
17312 DiagKind = diag::err_incompatible_qualified_id;
17315 DiagKind = diag::warn_incompatible_qualified_id;
17321 DiagKind = diag::err_incompatible_vectors;
17324 DiagKind = diag::warn_incompatible_vectors;
17328 DiagKind = diag::err_arc_weak_unavailable_assign;
17334 *Complained =
true;
17338 DiagKind = diag::err_typecheck_convert_incompatible;
17340 MayHaveConvFixit =
true;
17342 MayHaveFunctionDiff =
true;
17351 FirstType = DstType;
17352 SecondType = SrcType;
17362 FirstType = SrcType;
17363 SecondType = DstType;
17372 FDiag << FirstType << SecondType << ActionForDiag
17375 if (DiagKind == diag::ext_typecheck_convert_incompatible_pointer_sign ||
17376 DiagKind == diag::err_typecheck_convert_incompatible_pointer_sign) {
17386 if (!ConvHints.
isNull()) {
17391 if (MayHaveConvFixit) { FDiag << (
unsigned) (ConvHints.
Kind); }
17393 if (MayHaveFunctionDiff)
17397 if ((DiagKind == diag::warn_incompatible_qualified_id ||
17398 DiagKind == diag::err_incompatible_qualified_id) &&
17400 Diag(IFace->
getLocation(), diag::note_incomplete_class_and_qualified_id)
17407 if (CheckInferredResultType)
17414 *Complained =
true;
17425 return S.
Diag(Loc, diag::err_ice_not_integral)
17429 return S.
Diag(Loc, diag::err_expr_not_ice) << S.
LangOpts.CPlusPlus;
17444 IDDiagnoser(
unsigned DiagID)
17448 return S.
Diag(Loc, DiagID);
17450 } Diagnoser(DiagID);
17463 return S.
Diag(Loc, diag::ext_expr_not_ice) << S.
LangOpts.CPlusPlus;
17485 BaseDiagnoser(BaseDiagnoser) {}
17494 return S.
Diag(Loc, diag::err_ice_incomplete_type) << T;
17499 return S.
Diag(Loc, diag::err_ice_explicit_conversion) << T << ConvTy;
17510 return S.
Diag(Loc, diag::err_ice_ambiguous_conversion) << T;
17521 llvm_unreachable(
"conversion functions are permitted");
17523 } ConvertDiagnoser(Diagnoser);
17529 E = Converted.
get();
17544 E = RValueExpr.
get();
17551 if (!isa<ConstantExpr>(E))
17559 EvalResult.
Diag = &Notes;
17567 if (!isa<ConstantExpr>(E))
17582 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
17583 diag::note_invalid_subexpr_in_const_expr) {
17584 DiagLoc = Notes[0].first;
17588 if (!Folded || !CanFold) {
17592 Diag(Note.first, Note.second);
17600 Diag(Note.first, Note.second);
17610 class TransformToPE :
public TreeTransform<TransformToPE> {
17614 TransformToPE(
Sema &SemaRef) : BaseTransform(SemaRef) { }
17617 bool AlwaysRebuild() {
return true; }
17618 bool ReplacingOriginal() {
return true; }
17628 if (isa<FieldDecl>(E->
getDecl()) &&
17629 !SemaRef.isUnevaluatedContext())
17631 diag::err_invalid_non_static_member_use)
17634 return BaseTransform::TransformDeclRefExpr(E);
17642 return BaseTransform::TransformUnaryOperator(E);
17650 return SkipLambdaBody(E, Body);
17657 "Should only transform unevaluated expressions");
17662 return TransformToPE(*this).TransformExpr(E);
17667 "Should only transform unevaluated expressions");
17672 return TransformToPE(*this).TransformType(TInfo);
17680 LambdaContextDecl, ExprContext);
17687 .isDiscardedStatementContext();
17690 .isImmediateFunctionContext();
17709 if (
const auto *E = dyn_cast<UnaryOperator>(PossibleDeref)) {
17710 if (E->getOpcode() == UO_Deref)
17711 return CheckPossibleDeref(S, E->getSubExpr());
17712 }
else if (
const auto *E = dyn_cast<ArraySubscriptExpr>(PossibleDeref)) {
17713 return CheckPossibleDeref(S, E->getBase());
17714 }
else if (
const auto *E = dyn_cast<MemberExpr>(PossibleDeref)) {
17715 return CheckPossibleDeref(S, E->getBase());
17716 }
else if (
const auto E = dyn_cast<DeclRefExpr>(PossibleDeref)) {
17720 Inner = Ptr->getPointeeType();
17722 Inner = Arr->getElementType();
17726 if (Inner->hasAttr(attr::NoDeref))
17736 const DeclRefExpr *DeclRef = CheckPossibleDeref(*
this, E);
17743 Diag(E->
getExprLoc(), diag::warn_dereference_of_noderef_type_no_decl)
17762 if (BO->getOpcode() == BO_Assign) {
17764 llvm::erase_value(LHSs, BO->getLHS());
17781 if (
auto *DeclRef =
17782 dyn_cast<DeclRefExpr>(Call->getCallee()->IgnoreImplicit()))
17795 ExprEvalContexts.back().ImmediateInvocationCandidates.emplace_back(Res, 0);
17803 Eval.
Diag = &Notes;
17807 if (!Result || !Notes.empty()) {
17809 if (
auto *
FunctionalCast = dyn_cast<CXXFunctionalCastExpr>(InnerExpr))
17812 if (
auto *Call = dyn_cast<CallExpr>(InnerExpr))
17813 FD = cast<FunctionDecl>(Call->getCalleeDecl());
17814 else if (
auto *Call = dyn_cast<CXXConstructExpr>(InnerExpr))
17815 FD = Call->getConstructor();
17817 llvm_unreachable(
"unhandled decl kind");
17819 SemaRef.
Diag(CE->
getBeginLoc(), diag::err_invalid_consteval_call) << FD;
17822 SemaRef.
Diag(
Context->Loc, diag::note_invalid_consteval_initializer)
17824 SemaRef.
Diag(
Context->Decl->getBeginLoc(), diag::note_declared_at);
17826 for (
auto &Note : Notes)
17827 SemaRef.
Diag(Note.first, Note.second);
17838 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
17842 ComplexRemove(
Sema &SemaRef, llvm::SmallPtrSetImpl<DeclRefExpr *> &DR,
17845 4>::reverse_iterator Current)
17846 :
Base(SemaRef), DRSet(DR), IISet(II), CurrentII(Current) {}
17848 auto It = std::find_if(CurrentII, IISet.rend(),
17850 return Elem.getPointer() == E;
17852 assert(It != IISet.rend() &&
17853 "ConstantExpr marked IsImmediateInvocation should "
17859 return Base::TransformConstantExpr(E);
17860 RemoveImmediateInvocation(E);
17861 return Base::TransformExpr(E->
getSubExpr());
17867 return Base::TransformCXXOperatorCallExpr(E);
17876 if (
auto *CE = dyn_cast<ConstantExpr>(Init))
17877 if (CE->isImmediateInvocation())
17878 RemoveImmediateInvocation(CE);
17879 return Base::TransformInitializer(Init, NotCopyInit);
17890 bool AlwaysRebuild() {
return false; }
17891 bool ReplacingOriginal() {
return true; }
17892 bool AllowSkippingCXXConstructExpr() {
17893 bool Res = AllowSkippingFirstCXXConstructExpr;
17894 AllowSkippingFirstCXXConstructExpr =
true;
17897 bool AllowSkippingFirstCXXConstructExpr =
true;
17907 if (isa<CXXConstructExpr>(It->getPointer()->IgnoreImplicit()))
17908 Transformer.AllowSkippingFirstCXXConstructExpr =
false;
17910 ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
17916 It->getPointer()->setSubExpr(Res.
get());
17948 llvm::SmallPtrSetImpl<DeclRefExpr *> &DRSet;
17949 SimpleRemove(llvm::SmallPtrSetImpl<DeclRefExpr *> &S) : DRSet(S) {}
17952 return DRSet.size();
17955 Visitor.TraverseStmt(
17962 auto *FD = cast<FunctionDecl>(DR->getDecl());
17963 SemaRef.
Diag(DR->getBeginLoc(), diag::err_invalid_consteval_take_address)
17965 SemaRef.
Diag(FD->getLocation(), diag::note_declared_at);
17976 (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument ||
17984 D = diag::err_lambda_unevaluated_operand;
17990 D = diag::err_lambda_in_constant_expression;
17991 }
else if (Rec.
ExprContext == ExpressionKind::EK_TemplateArgument) {
17994 D = diag::err_lambda_in_invalid_context;
17996 llvm_unreachable(
"Couldn't infer lambda error message.");
17998 for (
const auto *L : Rec.
Lambdas)
17999 Diag(L->getBeginLoc(), D);
18010 Diag(BO->getBeginLoc(), diag::warn_deprecated_simple_assign_volatile)
18047 if (Result.isInvalid())
18083 llvm_unreachable(
"Invalid context");
18092 if (!TT.isOSWindows() || !TT.isX86())
18130 : FD(FD), Param(Param) {}
18137 CCName =
"stdcall";
18140 CCName =
"fastcall";
18143 CCName =
"vectorcall";
18146 llvm_unreachable(
"CC does not need mangling");
18149 S.
Diag(Loc, diag::err_cconv_incomplete_param_type)
18155 ParamIncompleteTypeDiagnoser Diagnoser(FD, Param);
18161 enum class OdrUseContext {
18177 OdrUseContext Result;
18192 Result = OdrUseContext::FormallyOdrUsed;
18198 Result = OdrUseContext::FormallyOdrUsed;
18203 return OdrUseContext::Dependent;
18214 auto *CCD = dyn_cast<CXXConstructorDecl>(Func);
18215 return CCD && CCD->getInheritedConstructor();
18221 bool MightBeOdrUse) {
18222 assert(Func &&
"No function?");
18237 OdrUseContext OdrUse =
18240 OdrUse = OdrUseContext::FormallyOdrUsed;
18246 if (
auto *Constructor = dyn_cast<CXXConstructorDecl>(Func))
18247 if (Constructor->isDefaultConstructor())
18248 OdrUse = OdrUseContext::FormallyOdrUsed;
18249 if (isa<CXXDestructorDecl>(Func))
18250 OdrUse = OdrUseContext::FormallyOdrUsed;
18257 bool NeededForConstantEvaluation =
18283 NeededForConstantEvaluation);
18290 if (NeedDefinition &&
18302 if (NeedDefinition && !Func->
getBody()) {
18305 dyn_cast<CXXConstructorDecl>(Func)) {
18306 Constructor = cast<CXXConstructorDecl>(Constructor->getFirstDecl());
18307 if (Constructor->isDefaulted() && !Constructor->isDeleted()) {
18308 if (Constructor->isDefaultConstructor()) {
18309 if (Constructor->isTrivial() &&
18310 !Constructor->hasAttr<DLLExportAttr>())
18313 }
else if (Constructor->isCopyConstructor()) {
18315 }
else if (Constructor->isMoveConstructor()) {
18318 }
else if (Constructor->getInheritedConstructor()) {
18322 dyn_cast<CXXDestructorDecl>(Func)) {
18323 Destructor = cast<CXXDestructorDecl>(Destructor->getFirstDecl());
18324 if (Destructor->isDefaulted() && !Destructor->isDeleted()) {
18325 if (Destructor->isTrivial() && !Destructor->hasAttr<DLLExportAttr>())
18329 if (Destructor->isVirtual() &&
getLangOpts().AppleKext)
18331 }
else if (
CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(Func)) {
18332 if (MethodDecl->isOverloadedOperator() &&
18333 MethodDecl->getOverloadedOperator() == OO_Equal) {
18334 MethodDecl = cast<CXXMethodDecl>(MethodDecl->getFirstDecl());
18335 if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) {
18336 if (MethodDecl->isCopyAssignmentOperator())
18338 else if (MethodDecl->isMoveAssignmentOperator())
18341 }
else if (isa<CXXConversionDecl>(MethodDecl) &&
18342 MethodDecl->getParent()->isLambda()) {
18344 cast<CXXConversionDecl>(MethodDecl->getFirstDecl());
18349 }
else if (MethodDecl->isVirtual() &&
getLangOpts().AppleKext)
18365 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
18366 if (FirstInstantiation) {
18367 PointOfInstantiation = Loc;
18369 MSI->setPointOfInstantiation(Loc);
18377 PointOfInstantiation = Loc;
18386 std::make_pair(Func, PointOfInstantiation));
18395 std::make_pair(Func, PointOfInstantiation));
18402 for (
auto *i : Func->
redecls()) {
18403 if (!i->isUsed(
false) && i->isImplicitlyInstantiable())
18415 if (Init->isInClassMemberInitializer())
18437 if (mightHaveNonExternalLinkage(Func))
18460 if (
auto *Dtor = dyn_cast<CXXDestructorDecl>(Func)) {
18462 if (
Parent->getNumVBases() > 0 && !Dtor->getBody())
18480 const unsigned *
const FunctionScopeIndexToStopAt =
nullptr) {
18483 VarDecl *Var =
V->getPotentiallyDecomposedVarDecl();
18484 assert(Var &&
"expected a capturable variable");
18494 QualType CaptureType, DeclRefType;
18500 DeclRefType, FunctionScopeIndexToStopAt);
18503 auto *FD = dyn_cast_or_null<FunctionDecl>(SemaRef.
CurContext);
18512 if (SemaRef.
LangOpts.CUDAIsDevice) {
18513 SemaRef.
targetDiag(Loc, diag::err_ref_bad_target)
18514 << 2 << 1 << Var << UserTarget;
18517 ? diag::note_cuda_const_var_unpromoted
18518 : diag::note_cuda_host_var);
18535 else if (SemaRef.
LangOpts.GPURelocatableDeviceCode)
18545 unsigned CapturingScopeIndex) {
18556 if (isa<ParmVarDecl>(
var) &&
18557 isa<TranslationUnitDecl>(VarDC))
18570 unsigned ValueKind = isa<BindingDecl>(
var) ? 1 : 0;
18572 if (isa<CXXMethodDecl>(VarDC) &&
18573 cast<CXXRecordDecl>(VarDC->
getParent())->isLambda()) {
18575 }
else if (isa<FunctionDecl>(VarDC)) {
18577 }
else if (isa<BlockDecl>(VarDC)) {
18581 S.
Diag(loc, diag::err_reference_to_local_in_enclosing_context)
18583 S.
Diag(
var->getLocation(), diag::note_entity_declared_at)
18592 bool &SubCapturesAreNested,
18598 SubCapturesAreNested =
true;
18611 !(isa<LambdaScopeInfo>(CSI) && cast<LambdaScopeInfo>(CSI)->Mutable) &&
18612 !(isa<CapturedRegionScopeInfo>(CSI) &&
18613 cast<CapturedRegionScopeInfo>(CSI)->CapRegionKind ==
CR_OpenMP))
18625 const bool Diagnose,
18645 assert((isa<VarDecl, BindingDecl>(Var)) &&
18646 "Only variables and structured bindings can be captured");
18648 bool IsBlock = isa<BlockScopeInfo>(CSI);
18649 bool IsLambda = isa<LambdaScopeInfo>(CSI);
18657 S.
Diag(Loc, diag::err_lambda_capture_anonymous_var);
18666 S.
Diag(Loc, diag::err_ref_vm_type);
18674 if (VTTy->getDecl()->hasFlexibleArrayMember()) {
18677 S.
Diag(Loc, diag::err_ref_flexarray_type);
18679 S.
Diag(Loc, diag::err_lambda_capture_flexarray_type) << Var;
18685 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
18688 if (HasBlocksAttr && (IsLambda || isa<CapturedRegionScopeInfo>(CSI))) {
18690 S.
Diag(Loc, diag::err_capture_block_variable) << Var << !IsLambda;
18699 S.
Diag(Loc, diag::err_opencl_block_ref_block);
18703 if (isa<BindingDecl>(Var)) {
18708 }
else if (Diagnose && S.
getLangOpts().CPlusPlus) {
18710 ? diag::warn_cxx17_compat_capture_binding
18711 : diag::ext_capture_binding)
18724 const bool Nested,
Sema &S,
bool Invalid) {
18725 bool ByRef =
false;
18731 if (BuildAndDiagnose) {
18732 S.
Diag(Loc, diag::err_ref_array_type);
18743 if (BuildAndDiagnose) {
18744 S.
Diag(Loc, diag::err_arc_autoreleasing_capture)
18760 if (BuildAndDiagnose) {
18762 S.
Diag(Loc, diag::warn_block_capture_autoreleasing);
18763 S.
Diag(VarLoc, diag::note_declare_parameter_strong);
18768 const bool HasBlocksAttr = Var->
hasAttr<BlocksAttr>();
18777 DeclRefType = CaptureType;
18781 if (BuildAndDiagnose)
18783 CaptureType, Invalid);
18791 const bool BuildAndDiagnose,
QualType &CaptureType,
QualType &DeclRefType,
18793 bool IsTopScope,
Sema &S,
bool Invalid) {
18818 CaptureType = DeclRefType;
18821 if (BuildAndDiagnose)
18822 RSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
18832 const bool RefersToCapturedVariable,
18835 Sema &S,
bool Invalid) {
18837 bool ByRef =
false;
18846 if (!Invalid && BD && S.
LangOpts.OpenMP) {
18847 if (BuildAndDiagnose) {
18848 S.
Diag(Loc, diag::err_capture_binding_openmp) << Var;
18881 if (!RefType->getPointeeType()->isFunctionType())
18888 if (BuildAndDiagnose) {
18889 S.
Diag(Loc, diag::err_arc_autoreleasing_capture) << 1;
18899 if (!Invalid && BuildAndDiagnose) {
18903 diag::err_capture_of_incomplete_or_sizeless_type,
18907 diag::err_capture_of_abstract_type))
18927 if (BuildAndDiagnose)
18928 LSI->
addCapture(Var,
false, ByRef, RefersToCapturedVariable,
18929 Loc, EllipsisLoc, CaptureType, Invalid);
18944 if (!(RD = RD->getDefinition()))
18946 if (RD->hasSimpleCopyConstructor())
18948 if (RD->hasUserDeclaredCopyConstructor())
18950 if (Ctor->isCopyConstructor())
18951 return !Ctor->isDeleted();
18971 if (ShouldOfferCopyFix) {
18975 FixBuffer.assign({Separator, Var->
getName()});
18976 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
18981 FixBuffer.assign({Separator,
"&", Var->
getName()});
18982 Sema.
Diag(VarInsertLoc, diag::note_lambda_variable_capture_fixit)
18994 return !C.isThisCapture() && !C.isInitCapture();
19003 if (ShouldOfferCopyFix) {
19004 bool CanDefaultCopyCapture =
true;
19013 if (CanDefaultCopyCapture && llvm::none_of(LSI->
Captures, [](
Capture &C) {
19014 return !C.isThisCapture() && !C.isInitCapture() && C.isCopyCapture();
19016 FixBuffer.assign({
"=", Separator});
19017 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19026 return !C.isInitCapture() && C.isReferenceCapture() &&
19027 !C.isThisCapture();
19029 FixBuffer.assign({
"&", Separator});
19030 Sema.
Diag(DefaultInsertLoc, diag::note_lambda_default_capture_fixit)
19039 QualType &DeclRefType,
const unsigned *
const FunctionScopeIndexToStopAt) {
19043 const auto *VD = dyn_cast<VarDecl>(Var);
19045 if (VD->isInitCapture())
19050 assert(VD &&
"Cannot capture a null variable");
19053 const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt
19057 if (FunctionScopeIndexToStopAt) {
19059 while (FSIndex != MaxFunctionScopesIndex) {
19068 if (VarDC == DC)
return true;
19072 bool IsGlobal = !VD->hasLocalStorage();
19075 MaxFunctionScopesIndex)))
19078 if (isa<VarDecl>(Var))
19089 CaptureType = Var->
getType();
19091 bool Nested =
false;
19093 unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
19106 FunctionScopesIndex = MaxFunctionScopesIndex - 1;
19127 if (BuildAndDiagnose) {
19130 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19145 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19146 QTy = PVD->getOriginalType();
19151 if (
auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
19157 Var, RSI->OpenMPLevel, RSI->OpenMPCaptureLevel);
19162 if (IsOpenMPPrivateDecl != OMPC_unknown &&
19165 if (
ParmVarDecl *PVD = dyn_cast_or_null<ParmVarDecl>(Var))
19166 QTy = PVD->getOriginalType();
19167 for (
int I = 1, E = getNumberOfConstructScopes(RSI->OpenMPLevel);
19169 auto *OuterRSI = cast<CapturedRegionScopeInfo>(
19171 assert(RSI->OpenMPLevel == OuterRSI->OpenMPLevel &&
19172 "Wrong number of captured regions associated with the "
19173 "OpenMP construct.");
19178 IsOpenMPPrivateDecl != OMPC_private &&
19180 RSI->OpenMPCaptureLevel);
19184 RSI->OpenMPCaptureLevel);
19190 adjustOpenMPTargetScopeIndex(FunctionScopesIndex, RSI->OpenMPLevel);
19192 if (IsTargetCap || IsOpenMPPrivateDecl == OMPC_private ||
19193 (IsGlobal && !IsGlobalCap)) {
19194 Nested = !IsTargetCap;
19209 if (BuildAndDiagnose) {
19210 Diag(ExprLoc, diag::err_lambda_impcap) << Var;
19212 auto *LSI = cast<LambdaScopeInfo>(CSI);
19214 Diag(LSI->Lambda->getBeginLoc(), diag::note_lambda_decl);
19232 FunctionScopesIndex--;
19235 }
while (!VarDC->
Equals(DC));
19242 bool Invalid =
false;
19243 for (
unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; I != N;
19256 if (Invalid && !BuildAndDiagnose)
19260 Invalid = !
captureInBlock(BSI, Var, ExprLoc, BuildAndDiagnose, CaptureType,
19261 DeclRefType, Nested, *
this, Invalid);
19265 RSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested,
19266 Kind, I == N - 1, *
this, Invalid);
19272 DeclRefType, Nested,
Kind, EllipsisLoc,
19273 I == N - 1, *
this, Invalid);
19277 if (Invalid && !BuildAndDiagnose)
19289 DeclRefType,
nullptr);
19296 false, CaptureType,
19297 DeclRefType,
nullptr);
19306 false, CaptureType,
19307 DeclRefType,
nullptr))
19310 return DeclRefType;
19318 class CopiedTemplateArgs {
19322 template<
typename RefExpr>
19323 CopiedTemplateArgs(RefExpr *E) : HasArgs(E->hasExplicitTemplateArgs()) {
19325 E->copyTemplateArgumentsInto(TemplateArgStorage);
19328 #ifdef __has_cpp_attribute
19329 #
if __has_cpp_attribute(clang::lifetimebound)
19330 [[clang::lifetimebound]]
19334 return HasArgs ? &TemplateArgStorage :
nullptr;
19360 auto Rebuild = [&](
Expr *Sub) {
19365 auto IsPotentialResultOdrUsed = [&](
NamedDecl *D) {
19368 auto *VD = dyn_cast<VarDecl>(D);
19391 llvm_unreachable(
"unexpected non-odr-use-reason");
19395 if (VD->getType()->isReferenceType())
19397 if (
auto *RD = VD->getType()->getAsCXXRecordDecl())
19398 if (RD->hasMutableFields())
19400 if (!VD->isUsableInConstantExpressions(S.
Context))
19405 if (VD->getType()->isReferenceType())
19413 auto MarkNotOdrUsed = [&] {
19416 LSI->markVariableExprAsNonODRUsed(E);
19423 case Expr::DeclRefExprClass: {
19424 auto *DRE = cast<DeclRefExpr>(E);
19425 if (DRE->isNonOdrUse() || IsPotentialResultOdrUsed(DRE->getDecl()))
19431 S.
Context, DRE->getQualifierLoc(), DRE->getTemplateKeywordLoc(),
19432 DRE->getDecl(), DRE->refersToEnclosingVariableOrCapture(),
19433 DRE->getNameInfo(), DRE->getType(), DRE->getValueKind(),
19434 DRE->getFoundDecl(), CopiedTemplateArgs(DRE), NOUR);
19437 case Expr::FunctionParmPackExprClass: {
19438 auto *FPPE = cast<FunctionParmPackExpr>(E);
19442 if (IsPotentialResultOdrUsed(D))
19453 case Expr::ArraySubscriptExprClass: {
19454 auto *ASE = cast<ArraySubscriptExpr>(E);
19459 if (!
Base.isUsable())
19461 Expr *LHS = ASE->getBase() == ASE->getLHS() ?
Base.get() : ASE->getLHS();
19462 Expr *RHS = ASE->getBase() == ASE->getRHS() ?
Base.get() : ASE->getRHS();
19465 ASE->getRBracketLoc());
19468 case Expr::MemberExprClass: {
19469 auto *ME = cast<MemberExpr>(E);
19472 if (isa<FieldDecl>(ME->getMemberDecl())) {
19474 if (!
Base.isUsable())
19477 S.
Context,
Base.get(), ME->isArrow(), ME->getOperatorLoc(),
19478 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(),
19479 ME->getMemberDecl(), ME->getFoundDecl(), ME->getMemberNameInfo(),
19480 CopiedTemplateArgs(ME), ME->getType(), ME->getValueKind(),
19481 ME->getObjectKind(), ME->isNonOdrUse());
19484 if (ME->getMemberDecl()->isCXXInstanceMember())
19489 if (ME->isNonOdrUse() || IsPotentialResultOdrUsed(ME->getMemberDecl()))
19495 S.
Context, ME->getBase(), ME->isArrow(), ME->getOperatorLoc(),
19496 ME->getQualifierLoc(), ME->getTemplateKeywordLoc(), ME->getMemberDecl(),
19497 ME->getFoundDecl(), ME->getMemberNameInfo(), CopiedTemplateArgs(ME),
19498 ME->getType(), ME->getValueKind(), ME->getObjectKind(), NOUR);
19501 case Expr::BinaryOperatorClass: {
19502 auto *BO = cast<BinaryOperator>(E);
19503 Expr *LHS = BO->getLHS();
19504 Expr *RHS = BO->getRHS();
19506 if (BO->getOpcode() == BO_PtrMemD) {
19508 if (!Sub.isUsable())
19512 }
else if (BO->getOpcode() == BO_Comma) {
19514 if (!Sub.isUsable())
19520 return S.
BuildBinOp(
nullptr, BO->getOperatorLoc(), BO->getOpcode(),
19525 case Expr::ParenExprClass: {
19526 auto *PE = cast<ParenExpr>(E);
19528 if (!Sub.isUsable())
19530 return S.
ActOnParenExpr(PE->getLParen(), PE->getRParen(), Sub.get());
19535 case Expr::ConditionalOperatorClass: {
19536 auto *CO = cast<ConditionalOperator>(E);
19546 LHS = CO->getLHS();
19548 RHS = CO->getRHS();
19550 CO->getCond(), LHS.
get(), RHS.
get());
19555 case Expr::UnaryOperatorClass: {
19556 auto *UO = cast<UnaryOperator>(E);
19557 if (UO->getOpcode() != UO_Extension)
19560 if (!Sub.isUsable())
19562 return S.
BuildUnaryOp(
nullptr, UO->getOperatorLoc(), UO_Extension,
19569 case Expr::GenericSelectionExprClass: {
19570 auto *GSE = cast<GenericSelectionExpr>(E);
19573 bool AnyChanged =
false;
19574 for (
Expr *OrigAssocExpr : GSE->getAssocExprs()) {
19575 ExprResult AssocExpr = Rebuild(OrigAssocExpr);
19579 AssocExprs.push_back(AssocExpr.
get());
19582 AssocExprs.push_back(OrigAssocExpr);
19587 GSE->getGenericLoc(), GSE->getDefaultLoc(),
19588 GSE->getRParenLoc(), GSE->getControllingExpr(),
19589 GSE->getAssocTypeSourceInfos(), AssocExprs)
19597 case Expr::ChooseExprClass: {
19598 auto *CE = cast<ChooseExpr>(E);
19608 if (!LHS.
get() && !RHS.
get())
19611 LHS = CE->getLHS();
19613 RHS = CE->getRHS();
19616 RHS.
get(), CE->getRParenLoc());
19620 case Expr::ConstantExprClass: {
19621 auto *CE = cast<ConstantExpr>(E);
19623 if (!Sub.isUsable())
19630 case Expr::ImplicitCastExprClass: {
19631 auto *ICE = cast<ImplicitCastExpr>(E);
19635 switch (ICE->getCastKind()) {
19637 case CK_DerivedToBase:
19638 case CK_UncheckedDerivedToBase: {
19639 ExprResult Sub = Rebuild(ICE->getSubExpr());
19640 if (!Sub.isUsable())
19644 ICE->getValueKind(), &Path);
19679 if (Result.isInvalid())
19681 return Result.get() ? Result : E;
19703 for (
Expr *E : LocalMaybeODRUseExprs) {
19704 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
19706 DRE->getLocation(), *
this);
19707 }
else if (
auto *ME = dyn_cast<MemberExpr>(E)) {
19710 }
else if (
auto *FP = dyn_cast<FunctionParmPackExpr>(E)) {
19714 llvm_unreachable(
"Unexpected expression");
19719 "MarkVarDeclODRUsed failed to cleanup MaybeODRUseExprs?");
19728 const bool RefersToEnclosingScope =
19731 if (RefersToEnclosingScope) {
19746 assert(E &&
"Capture variable should be used in an expression.");
19757 assert((!E || isa<DeclRefExpr>(E) || isa<MemberExpr>(E) ||
19758 isa<FunctionParmPackExpr>(E)) &&
19759 "Invalid Expr argument to DoMarkVarDeclReferenced");
19770 bool UsableInConstantExpr =
19782 bool NeededForConstantEvaluation =
19785 bool NeedDefinition =
19788 assert(!isa<VarTemplatePartialSpecializationDecl>(Var) &&
19789 "Can't instantiate a partial template specialization.");
19795 !isa<VarTemplateSpecializationDecl>(Var))
19806 bool TryInstantiating =
19810 if (TryInstantiating) {
19813 bool FirstInstantiation = PointOfInstantiation.
isInvalid();
19814 if (FirstInstantiation) {
19815 PointOfInstantiation = Loc;
19817 MSI->setPointOfInstantiation(PointOfInstantiation);
19823 if (UsableInConstantExpr) {
19832 if (
auto *DRE = dyn_cast_or_null<DeclRefExpr>(E))
19833 DRE->setDecl(DRE->getDecl());
19834 else if (
auto *ME = dyn_cast_or_null<MemberExpr>(E))
19835 ME->setMemberDecl(ME->getMemberDecl());
19836 }
else if (FirstInstantiation ||
19837 isa<VarTemplateSpecializationDecl>(Var)) {
19844 .push_back(std::make_pair(Var, PointOfInstantiation));
19868 if (
DeclRefExpr *DRE = dyn_cast_or_null<DeclRefExpr>(E))
19869 if (DRE->isNonOdrUse())
19871 if (
MemberExpr *ME = dyn_cast_or_null<MemberExpr>(E))
19872 if (ME->isNonOdrUse())
19879 assert((!E || isa<FunctionParmPackExpr>(E) ||
19881 "missing non-odr-use marking for unevaluated decl ref");
19884 case OdrUseContext::FormallyOdrUsed:
19898 case OdrUseContext::Dependent:
19917 QualType CaptureType, DeclRefType;
19923 }
else if (OdrUse == OdrUseContext::Dependent) {
19937 bool MightBeOdrUse,
19942 if (
VarDecl *Var = dyn_cast<VarDecl>(D)) {
19956 const MemberExpr *ME = dyn_cast<MemberExpr>(E);
19963 bool IsVirtualCall = MD->
isVirtual() &&
19965 if (!IsVirtualCall)
19984 bool OdrUse =
true;
19986 if (Method->isVirtual() &&
19990 if (
auto *FD = dyn_cast<FunctionDecl>(E->
getDecl()))
20008 bool MightBeOdrUse =
true;
20011 if (Method->isPure())
20012 MightBeOdrUse =
false;
20032 bool MightBeOdrUse) {
20033 if (MightBeOdrUse) {
20034 if (
auto *VD = dyn_cast<VarDecl>(D)) {
20039 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
20067 bool MarkReferencedDecls::TraverseTemplateArgument(
20081 return Inherited::TraverseTemplateArgument(Arg);
20085 MarkReferencedDecls Marker(*
this, Loc);
20086 Marker.TraverseType(T);
20092 class EvaluatedExprMarker :
public UsedDeclVisitor<EvaluatedExprMarker> {
20095 bool SkipLocalVariables;
20098 EvaluatedExprMarker(
Sema &S,
bool SkipLocalVariables,
20100 : Inherited(S), SkipLocalVariables(SkipLocalVariables), StopAt(StopAt) {}
20106 void Visit(
Expr *E) {
20107 if (llvm::is_contained(StopAt, E))
20109 Inherited::Visit(E);
20119 if (SkipLocalVariables) {
20121 if (VD->hasLocalStorage())
20145 bool SkipLocalVariables,
20147 EvaluatedExprMarker(*
this, SkipLocalVariables, StopAt).Visit(E);
20169 if (
auto *VD = dyn_cast_or_null<VarDecl>(
20171 if (VD->isConstexpr() ||
20172 (VD->isStaticDataMember() && VD->isFirstDecl() && !VD->isInline()))
20244 class CallReturnIncompleteDiagnoser :
public TypeDiagnoser {
20250 : FD(FD), CE(CE) { }
20254 S.
Diag(Loc, diag::err_call_incomplete_return)
20259 S.
Diag(Loc, diag::err_call_function_incomplete_return)
20264 } Diagnoser(FD, CE);
20277 unsigned diagnostic = diag::warn_condition_is_assignment;
20278 bool IsOrAssign =
false;
20281 if (Op->getOpcode() != BO_Assign && Op->getOpcode() != BO_OrAssign)
20284 IsOrAssign = Op->getOpcode() == BO_OrAssign;
20293 diagnostic = diag::warn_condition_is_idiomatic_assignment;
20297 diagnostic = diag::warn_condition_is_idiomatic_assignment;
20300 Loc = Op->getOperatorLoc();
20302 if (Op->getOperator() != OO_Equal && Op->getOperator() != OO_PipeEqual)
20305 IsOrAssign = Op->getOperator() == OO_PipeEqual;
20306 Loc = Op->getOperatorLoc();
20318 Diag(Loc, diag::note_condition_assign_silence)
20323 Diag(Loc, diag::note_condition_or_assign_to_comparison)
20326 Diag(Loc, diag::note_condition_assign_to_comparison)
20344 if (opE->getOpcode() == BO_EQ &&
20345 opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(
Context)
20351 Diag(Loc, diag::note_equality_comparison_silence)
20354 Diag(Loc, diag::note_equality_comparison_to_assign)
20360 bool IsConstexpr) {
20362 if (
ParenExpr *parenE = dyn_cast<ParenExpr>(E))
20380 Diag(Loc, diag::err_typecheck_statement_requires_scalar)
20384 CheckBoolLikeConversion(E, Loc);
20430 struct RebuildUnknownAnyFunction
20431 :
StmtVisitor<RebuildUnknownAnyFunction, ExprResult> {
20435 RebuildUnknownAnyFunction(
Sema &S) : S(S) {}
20438 llvm_unreachable(
"unexpected statement!");
20449 template <
class T>
ExprResult rebuildSugarExpr(T *E) {
20450 ExprResult SubResult = Visit(E->getSubExpr());
20453 Expr *SubExpr = SubResult.
get();
20454 E->setSubExpr(SubExpr);
20462 return rebuildSugarExpr(E);
20466 return rebuildSugarExpr(E);
20473 Expr *SubExpr = SubResult.
get();
20482 if (!isa<FunctionDecl>(VD))
return VisitExpr(E);
20488 !(isa<CXXMethodDecl>(VD) &&
20489 cast<CXXMethodDecl>(VD)->isInstance()))
20500 return resolveDecl(E, E->
getDecl());
20508 ExprResult Result = RebuildUnknownAnyFunction(S).Visit(FunctionExpr);
20509 if (Result.isInvalid())
return ExprError();
20518 struct RebuildUnknownAnyExpr
20519 :
StmtVisitor<RebuildUnknownAnyExpr, ExprResult> {
20530 llvm_unreachable(
"unexpected statement!");
20544 template <
class T>
ExprResult rebuildSugarExpr(T *E) {
20545 ExprResult SubResult = Visit(E->getSubExpr());
20547 Expr *SubExpr = SubResult.
get();
20548 E->setSubExpr(SubExpr);
20556 return rebuildSugarExpr(E);
20560 return rebuildSugarExpr(E);
20598 return resolveDecl(E, E->
getDecl());
20609 FK_FunctionPointer,
20616 assert(isa<CXXMemberCallExpr>(E) || isa<CXXOperatorCallExpr>(E));
20617 Kind = FK_MemberFunction;
20621 Kind = FK_FunctionPointer;
20624 Kind = FK_BlockPointer;
20630 unsigned diagID = diag::err_func_returning_array_function;
20631 if (
Kind == FK_BlockPointer)
20632 diagID = diag::err_block_returning_array_function;
20668 if (ParamTypes.empty() && Proto->
isVariadic()) {
20670 for (
unsigned i = 0, e = E->
getNumArgs(); i != e; ++i) {
20673 ParamTypes = ArgTypes;
20684 case FK_MemberFunction:
20688 case FK_FunctionPointer:
20692 case FK_BlockPointer:
20698 ExprResult CalleeResult = Visit(CalleeExpr);
20709 S.
Diag(E->
getExprLoc(), diag::err_func_returning_array_function)
20717 Method->setReturnType(DestType);
20729 if (E->
getCastKind() == CK_FunctionToPointerDecay) {
20739 if (!Result.isUsable())
return ExprError();
20743 }
else if (E->
getCastKind() == CK_LValueToRValue) {
20747 assert(isa<BlockPointerType>(E->
getType()));
20755 if (!Result.isUsable())
return ExprError();
20760 llvm_unreachable(
"Unhandled cast type!");
20775 if (Result.isInvalid())
return ExprError();
20793 if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) {
20796 S.
Context, FD->getDeclContext(), Loc, Loc,
20797 FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(),
20799 false , FD->hasPrototype(),
20802 if (FD->getQualifier())
20806 for (
const auto &AI : FT->param_types()) {
20810 Params.push_back(Param);
20812 NewFD->setParams(Params);
20819 if (MD->isInstance()) {
20829 }
else if (isa<VarDecl>(VD)) {
20833 S.
Diag(E->
getExprLoc(), diag::err_unknown_any_var_function_type)
20861 diag::err_typecheck_cast_to_incomplete))
20876 return RebuildUnknownAnyExpr(*
this, ToType).Visit(E);
20892 assert(!
arg->hasPlaceholderType());
20904 unsigned diagID = diag::err_uncasted_use_of_unknown_any;
20907 if (
CallExpr *call = dyn_cast<CallExpr>(E)) {
20908 E = call->getCallee();
20909 diagID = diag::err_uncasted_call_of_unknown_any;
20917 if (
DeclRefExpr *ref = dyn_cast<DeclRefExpr>(E)) {
20918 loc = ref->getLocation();
20919 d = ref->getDecl();
20920 }
else if (
MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
20921 loc = mem->getMemberLoc();
20922 d = mem->getMemberDecl();
20924 diagID = diag::err_uncasted_call_of_unknown_any;
20925 loc = msg->getSelectorStartLoc();
20926 d = msg->getMethodDecl();
20928 S.
Diag(loc, diag::err_uncasted_send_to_unknown_any_method)
20929 <<
static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector()
20953 if (!Result.isUsable())
return ExprError();
20958 if (!placeholderType)
return E;
20960 switch (placeholderType->
getKind()) {
20963 case BuiltinType::Overload: {
20983 case BuiltinType::BoundMember: {
20988 if (isa<CXXPseudoDestructorExpr>(BME)) {
20989 PD =
PDiag(diag::err_dtor_expr_without_call) << 1;
20990 }
else if (
const auto *ME = dyn_cast<MemberExpr>(BME)) {
20991 if (ME->getMemberNameInfo().getName().getNameKind() ==
20993 PD =
PDiag(diag::err_dtor_expr_without_call) << 0;
21001 case BuiltinType::ARCUnbridgedCast: {
21008 case BuiltinType::UnknownAny:
21012 case BuiltinType::PseudoObject:
21015 case BuiltinType::BuiltinFn: {
21019 auto *FD = cast<FunctionDecl>(DRE->
getDecl());
21020 unsigned BuiltinID = FD->getBuiltinID();
21021 if (BuiltinID == Builtin::BI__noop) {
21023 CK_BuiltinFnToFnPtr)
21036 ? diag::err_use_of_unaddressable_function
21037 : diag::warn_cxx20_compat_use_of_unaddressable_function);
21038 if (FD->isImplicitlyInstantiable()) {
21065 case BuiltinType::IncompleteMatrixIdx:
21069 diag::err_matrix_incomplete_index);
21073 case BuiltinType::OMPArraySection:
21078 case BuiltinType::OMPArrayShaping:
21081 case BuiltinType::OMPIterator:
21085 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
21086 case BuiltinType::Id:
21087 #include "clang/Basic/OpenCLImageTypes.def"
21088 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
21089 case BuiltinType::Id:
21090 #include "clang/Basic/OpenCLExtensionTypes.def"
21091 #define SVE_TYPE(Name, Id, SingletonId) \
21092 case BuiltinType::Id:
21093 #include "clang/Basic/AArch64SVEACLETypes.def"
21094 #define PPC_VECTOR_TYPE(Name, Id, Size) \
21095 case BuiltinType::Id:
21096 #include "clang/Basic/PPCTypes.def"
21097 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
21098 #include "clang/Basic/RISCVVTypes.def"
21099 #define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id:
21100 #define PLACEHOLDER_TYPE(Id, SingletonId)
21101 #include "clang/AST/BuiltinTypes.def"
21105 llvm_unreachable(
"invalid placeholder type!");
21119 assert((
Kind == tok::kw___objc_yes ||
Kind == tok::kw___objc_no) &&
21120 "Unknown Objective-C Boolean value!");
21140 auto FindSpecVersion =
21141 [&](StringRef Platform) -> std::optional<VersionTuple> {
21147 if (Spec == AvailSpecs.end() && Platform ==
"maccatalyst") {
21152 if (Spec == AvailSpecs.end())
21153 return std::nullopt;
21157 VersionTuple Version;
21158 if (
auto MaybeVersion =
21160 Version = *MaybeVersion;
21165 Context->HasPotentialAvailabilityViolations =
true;